Info DB

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)
[{'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']}, {'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']}]

For Loop

This is for loop example

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()
For loop output

Chris Stewart Albertson
	 Residence: San Diego
	 Birth Day: January 20
	 Cars: 2022-Toyota Tacoma
	 Show: Breaking Bad
	 Games: GTA
Eli David Gilmore
	 Residence: San Diego
	 Birth Day: Aug 16
	 Cars: 2016-Nissan Altima
	 Show: The Flash
	 Games: Minecraft

Recursive Loop

This is for the recursive 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)
Recursive loop output:

Chris Stewart Albertson
	 Residence: San Diego
	 Birth Day: January 20
	 Cars: 2022-Toyota Tacoma
	 Show: Breaking Bad
	 Games: GTA
Eli David Gilmore
	 Residence: San Diego
	 Birth Day: Aug 16
	 Cars: 2016-Nissan Altima
	 Show: The Flash
	 Games: Minecraft

While Loop

This is for the While Loop example

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()
While loop output

Chris Stewart Albertson
	 Residence: San Diego
	 Birth Day: January 20
	 Cars: 2022-Toyota Tacoma
	 Show: Breaking Bad
	 Games: GTA
Eli David Gilmore
	 Residence: San Diego
	 Birth Day: Aug 16
	 Cars: 2016-Nissan Altima
	 Show: The Flash
	 Games: Minecraft

Reverse List

This is for the reverse list example

list = ["1", "2", "3", "4", "5", "6"]
print('Regular List:', list)
list.reverse()
print('Reversed List:', list)
Regular List: ['1', '2', '3', '4', '5', '6']
Reversed List: ['6', '5', '4', '3', '2', '1']

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!")
Take this quiz about planes.
What is the biggest thing in our Universe
The Boralis Great Wall
Incorrect, the answer was;  The Boralis Great Wall 
Who owns Space X
Elon Musk
Correct, you have  1  points!
What does NASA stand for
 National Aeronautics and Space Administration
Correct, you have  2  points!
What planet is closest to our Sun
Mercury
Correct, you have  3  points!
You have finished the quiz with  3  out of  4  points!