Python Dictionaries
Week 2 Hacks
myDict = []
#my dictionary below
myDict.append({
"FirstName": "Yuri",
"LastNameInitial": "S.",
"DOB": "Janurary 3",
"Residence": "San Diego",
"Family Members": "4",
"Age": "15"
})
myDict.append({
"FirstName": "Tanay",
"LastNameInitial": "P.",
"DOB": "July 24",
"Residence": "San Diego",
"Family Members": "3",
"Age": "15"
})
print(myDict)
def print_data(d_rec):
print(d_rec["FirstName"], d_rec["LastNameInitial"]) # using comma puts space between values
print("\t", "DOB:", d_rec["DOB"]) # \t is a tab indent
print("\t", "Residence:", d_rec["Residence"]) # \t is a tab indent
print("\t", "Family Members:", d_rec["Family Members"]) # \t is a tab indent
print("\t", "Age:", d_rec["Age"]) # \t is a tab indent
print()
def loop_data():
print("Looped data below \n")
for i in myDict:
print_data(i)
loop_data()
myDict = []
#my dictionary below
myDict.append({
"FirstName": "Yuri",
"LastNameInitial": "S.",
"DOB": "Janurary 3",
"Residence": "San Diego",
"Family Members": "4",
"Age": "15"
})
myDict.append({
"FirstName": "Tanay",
"LastNameInitial": "P.",
"DOB": "July 24",
"Residence": "San Diego",
"Family Members": "3",
"Age": "15"
})
for i in range(len(myDict)):
print(myDict[i-1])
dictionary = ({
"What does STR stand for in python? ": "String",
"What does INT stand for in python? ": "Integer",
"What function prints anything into the terminal? ": "Print",
})
#scoring system
score = 0
for key,value in dictionary.items():
questions = input(f"{key}")
if questions == value:
print("Correct")
score += 1
else:
print("Incorrect")
print(score)