InfoDb

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)
[{'FirstName': 'elijah', 'MiddleName': 'david', 'LastName': 'gilmour', 'DOB': 'august 8', 'Residence': 'San Diego', 'Owns_Cars': '2013 nissan altima', 'Show': 'Flash', 'Game': 'warzone'}, {'FirstName': 'Christopher', 'MiddleName': 'stewart', 'LastName': 'albertson', 'DOB': 'january 20', 'Residence': 'San Diego', 'Owns_Cars': '2022 toyota Tacoma', 'Show': 'Breaking bad', 'Game': 'GTA'}]

Reversed List

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']

Random List

import random

print('Regular List:', list)
random.shuffle(list)
print('Random List:', list)
Regular List: ['6', '5', '4', '3', '2', '1']
Random List: ['1', '2', '3', '6', '5', '4']

Loop

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

elijah david gilmour
	 Residence: San Diego
	 Birth Day: august 8
	 Cars:  2013 nissan altima
	 Favorite show:  Flash
	 Favorite game:  warzone
Christopher stewart albertson
	 Residence: San Diego
	 Birth Day: january 20
	 Cars:  2022 toyota Tacoma
	 Favorite show:  Breaking bad
	 Favorite game:  GTA

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

elijah david gilmour
	 Residence: San Diego
	 Birth Day: august 8
	 Cars:  2013 nissan altima
	 Favorite show:  Flash
	 Favorite game:  warzone
Christopher stewart albertson
	 Residence: San Diego
	 Birth Day: january 20
	 Cars:  2022 toyota Tacoma
	 Favorite show:  Breaking bad
	 Favorite game:  GTA

Recersive 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)
Recursive loop output

elijah david gilmour
	 Residence: San Diego
	 Birth Day: august 8
	 Cars:  2013 nissan altima
	 Favorite show:  Flash
	 Favorite game:  warzone
Christopher stewart albertson
	 Residence: San Diego
	 Birth Day: january 20
	 Cars:  2022 toyota Tacoma
	 Favorite show:  Breaking bad
	 Favorite game:  GTA

Quiz using dictionaries lists

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!")
Take this quiz about football rules.
How mnay yards is a football field
120 yards
Correct, you have  1  points!
How many yards is the endzone
10 yards
Correct, you have  2  points!
How many yards is a first down penalty
5 yards
Incorrect, the answer was;  10 yards
how many players is on the offense
11
Incorrect, the answer was;  11 players
You have finished the quiz with  2  out of  4  points!