InfoDb = []
# To add data to InfoDB we must use the .append function
# A dictionary is made with curly braces {}
InfoDb.append({
"FirstName": "elijah",
"MiddleName": "david",
"LastName": "gilmour",
"DOB": "august 8",
"Residence": "San Diego",
"Owns_Cars": "2013 nissan altima",
"Show": "Flash",
"Game": "warzone"
})
InfoDb.append({
"FirstName": "Christopher",
"MiddleName": "stewart",
"LastName": "albertson",
"DOB": "january 20",
"Residence": "San Diego",
"Owns_Cars": "2022 toyota Tacoma",
"Show": "Breaking bad",
"Game": "GTA"
})
# Print the data structure
print(InfoDb)
list = ["1", "2", "3", "4", "5", "6"]
print('Regular List:', list)
list.reverse()
print('Reversed List:', list)
import random
print('Regular List:', list)
random.shuffle(list)
print('Random List:', list)
def print_data(d_rec): # defines function that prints data
print(d_rec["FirstName"], d_rec["MiddleName"], d_rec["LastName"]) # prints data from the dictionary
print("\t", "Residence:", d_rec["Residence"])
print("\t", "Birth Day:", d_rec["DOB"])
print("\t", "Cars: ", d_rec["Owns_Cars"]) # end="" make sure no return occurs
print("\t", "Favorite show: ", d_rec["Show"])
print("\t", "Favorite game: ", d_rec["Game"])
# 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 while_loop():
print("While loop output\n")
i = 0
while i < len(InfoDb):
record = InfoDb[i]
print_data(record)
i += 1
return
while_loop()
def recursive_loop(i):
if i < len(InfoDb):
record = InfoDb[i]
print_data(record)
recursive_loop(i + 1)
return
print("Recursive loop output\n")
recursive_loop(0)
question = [] # creates empty list
question.append({ # adds dictionary with question and answer to list using .append
"Question": "How mnay yards is a football field",
"Answer": "120 yards",
})
question.append({
"Question": "How many yards is the endzone",
"Answer": "10 yards",
})
question.append({
"Question": "How many yards is a first down penalty",
"Answer": "10 yards",
})
question.append({
"Question": "how many players is on the offense",
"Answer": "11 players",
})
points = 0
print("Take this quiz about football rules.")
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!")