Python List
Exploring lists
InfoDb = []
print ("Hello, you will be asked a few questions.\nAre you ready?")
rsp = input ("Are you ready?")
if rsp == "yes":
print ("Great!\n")
if rsp == "no" :
print ("That's too bad.\n")
print ("What is your name?")
name = input ('What is your name?\n')
print ("Hello " + name + "! How old are you?")
age = input ('How old are you?\n')
print (age + "! Alright, what's your favorite color?")
color = input ("What's your favorite color?\n")
print (color +"? I love that color too!")
print ("\nThanks for doing my quiz! Here is your info:\n")
InfoDb.append({
"Name" : name,
"Age" : age,
"Favorite color" : color
})
def print_data(d_rec):
print("Name:", d_rec["Name"]) # using comma puts space between values
print("Age:", d_rec["Age"])
print("Favorite Color:", d_rec["Favorite color"], end="") # end="" make sure no return occurs
print()
def for_loop():
for record in InfoDb:
print_data(record)
for_loop()