I created two versions, the first without keyboard input, and the second with keyboard input.
#version 1
dictionary = {"Bob": 16, "Mark": 15, "Elena": 17, "Tom": 13}
print("Age of my friends:\n")
for key in dictionary:
print(key, "-" ,str(dictionary[key]), "y.o.")
#version 2
dictionary = {}
name = input("Enter dictionary name: ")
key = None
while True:
key = input("Enter the key (0 if you want to finish filling): ")
if key != "0":
value = input("Enter the value: ")
dictionary[key] = value
else:
break
print("\n" + name + ":\n")
for key in dictionary:
print(key, "-" ,str(dictionary[key]))
Comments
Leave a comment