InfoDb = []
# Append to List a Dictionary of key/values related to a person and cars
InfoDb.append({
"FirstName": "Chris",
"LastName": "Albertson",
"MiddleName": "Stewart",
"DOB": "January 20",
"Residence": "San Diego",
"Email": "christopheralbertson@gmail.com",
"Owns_Cars": ["2022-Toyota Tacoma"],
"Favorite_Show": ["Breaking Bad"],
"Favorite_Games": ["GTA"]
})
# Append to List a 2nd Dictionary of key/values
InfoDb.append({
"FirstName": "Eli",
"LastName": "Gilmore",
"MiddleName": "David",
"DOB": "Aug 16",
"Residence": "San Diego",
"Email": "N/A",
"Owns_Cars": ["2016-Nissan Altima"],
"Favorite_Show": ["The Flash"],
"Favorite_Games": ["Minecraft"]
})
# Print the data structure
print(InfoDb)
def print_data(d_rec):
print(d_rec["FirstName"], d_rec["MiddleName"], d_rec["LastName"]) # using comma puts space between values
print("\t", "Residence:", d_rec["Residence"]) # \t is a tab indent
print("\t", "Birth Day:", d_rec["DOB"])
print("\t", "Cars: ", end="") # end="" make sure no return occurs
print(", ".join(d_rec["Owns_Cars"])) # join allows printing a string list with separator
print("\t", "Show: ", end="")
print(", ".join(d_rec["Favorite_Show"]))
print("\t", "Games: ", end="")
print(", ".join(d_rec["Favorite_Games"]))
# for loop iterates on length of InfoDb
def for_loop():
print("For loop output\n")
for record in InfoDb:
print_data(record)
for_loop()
def recursive_loop(i):
if i < len(InfoDb):
record = InfoDb[i]
print_data(record)
recursive_loop(i + 1)
return
print("\nRecursive loop output:\n")
recursive_loop(0)
def while_loop():
print("While loop output\n")
i = 0
while i < len(InfoDb):
record = InfoDb[i]
print_data(record)
i += 1
return
while_loop()
list = ["1", "2", "3", "4", "5", "6"]
print('Regular List:', list)
list.reverse()
print('Reversed List:', list)
Intersteller SPACE Quiz!
question = [] # creates empty list
question.append({ # adds dictionary with question and answer to list using .append
"Question": "What is the biggest thing in our Universe",
"Answer": "The Boralis Great Wall ",
})
question.append({
"Question": "Who owns Space X",
"Answer": "Elon Musk",
})
question.append({
"Question": "What does NASA stand for",
"Answer": " National Aeronautics and Space Administration",
})
question.append({
"Question": "What planet is closest to our Sun",
"Answer": "Mercury",
})
points = 0
print("Take this quiz about planes.")
for i in question: # for loop repeats every time an answer is given
print(i["Question"])
response = input(i["Question"])
print(response)
if response == i["Answer"]:
points += 1
print("Correct, you have ", points, " points!")
else:
print("Incorrect, the answer was; ", i["Answer"])
print("You have finished the quiz with ", points, " out of ", len(question), " points!")