Python Dictionaries: Medical Insurance Project


When completing the Python Dictionaries: Medical Insurance Project, the code pasted below leads to output that is in a random order each time it’s crunched. Marina’s age is therefore incorrect as well, I believe 4 out of 5 times it’s crunched. This is all strange to me, because almost all the lines of code were supplied individually by Codecademy just below each step.

names = {“Marina”, “Vinay”, “Connie”, “Isaac”, “Valentina”}
ages = {27, 24, 43, 35, 52}
zipped_ages = zip(names, ages)
names_to_ages = {key: value for key, value in zipped_ages}
marina_age = names_to_ages.get(“Marina”, None)
print("Marina’s age is " + str(marina_age))

Please advise.



You’re using curly braces {} for the objects you’re assigning to names and ages. This is the syntax for a set which is a very different type (unique elements that are unordered, hence the changing order you’re experiencing). You’re probably after the [] square brackets for a list or drop the enclosure for a tuple.

Worth a look at How do I format code in my posts? too which describes how to post nicely formatted code to the forum (for Python where indentation matters so much this is very helpful :slightly_smiling_face:).

1 Like

Awesome, thank you so much for your help!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.