Dictionaries With Loops
Loops and lists are a perfect pair. Dictionaries and loops are a bit trickier. This is because each dictionary item is made up of two parts - the name of the key and the actual value of that key
Eg:
myDictionary = {"name" : "David the Mildy Terrifying", "health": 186, "strength": 4, "equipped":"l33t haxx0r p0werz"}
for name,value in myDictionary.items():
print(f"{name}:{value}")
if (name == "strength"):
if value > 100:
print("Whoa, SO STRONG")
else:
print("Looks like you skipped leg day, arm day, chest day and, well, gym day entirely bro!")
Comments
Post a Comment