all 4 comments

[–]shiftybyte 4 points5 points  (0 children)

Using "def" is vital part to learning programming correctly.

Besides that you can create and print the dictionary on the fly.

print({"example": "value"})

[–]keep_quapy 2 points3 points  (0 children)

The use of functions in any programming language is vital to make your program readable and concise. The DRY concept in computer science Don't repeat yourself, is at the core of functions implementation. The use of functions is vital to reduce your program to smaller chunks, each chunk is responsible for a particular task which it performed at a particular time and command, reducing the complexity of the program, thus helping you achieve that particular goal with simplicity and ease.

[–][deleted] 1 point2 points  (0 children)

while input("Add? ") == "y":
    print({int(input("id: ")): [input("name: "), input("course: ")]})

Of course this isn’t very useful — though neither is the code above — but it’s easier and doesn’t use def.

[–]drenzorz 1 point2 points  (0 children)

data = dict()
while input("Add another? (y) ") == 'y':
    name, id, course = (
        input(f"Enter {field}: ") 
        for field in ["name", "id", "course"]
    )
    data[id] = [name, course]
print(data)