Lists, Dictionaries, Iterations
# Define an empty List called InfoDb
InfoDb = []
# InfoDB is a data structure with expected Keys and Values
# Append to List a Dictionary of key/values related to a person and cars
InfoDb.append({
"FirstName": "Nicolas",
"LastName": "Mosqueda",
"DOB": "July 19",
"Residence": "San Diego",
"Email": "nicomosqueda02@gmail.com",
"Cars": ["2013-Nissan Versa"],
"FavoriteFootballPlayers": ["Josh Allen", "Patrick Mahomes", "Russel Wilson"]
})
InfoDb.append({
"FirstName": "Ben",
"LastName": "Lee",
"DOB": "January 19",
"Residence": "San Diego",
"Email": "benjaminlee@gmail.com",
"Cars": ["Honda Civic"],
"FavoriteFootballPlayers": ["Tom Brady", "Patrick Mahomes", "Dak Prescott"]
})
# Print the data structure
print(InfoDb)
# Online Python - IDE, Editor, Compiler, Interpreter
# Define an empty List called InfoDb
InfoDb = []
# InfoDB is a data structure with expected Keys and Values
# Append to List a Dictionary of key/values related to a person and cars
InfoDb.append({
"FirstName": "Nicolas",
"LastName": "Mosqueda",
"DOB": "July 19",
"Residence": "San Diego",
"Email": "nicomosqueda02@gmail.com",
"Cars": ["2013-Nissan Versa"],
"FavoriteFootballPlayers": ["Josh Allen", "Patrick Mahomes", "Russel Wilson"]
})
InfoDb.append({
"FirstName": "Ben",
"LastName": "Lee",
"DOB": "January 19",
"Residence": "San Diego",
"Email": "benjaminlee@gmail.com",
"Cars": ["Honda Civic"],
"FavoriteFootballPlayers": ["Tom Brady", "Patrick Mahomes", "Dak Prescott"]
})
def printInfo(data):
print("FirstName: ", data["FirstName"])
print("LastName: ", data["LastName"])
print("DOB: ", data["DOB"])
print("Residence: ", data["Residence"])
print("Email: ", data["Email"])
print("FavoriteFootballPlayers: ", data["FavoriteFootballPlayers"])
# For Loop:
for val in InfoDb:
printInfo(val)
for index in range(len(InfoDb)):
printInfo(InfoDb[index])
index = 0
while index < len(InfoDb):
printInfo(InfoDb[index])
index+=1
def recursion(i):
if i >= len(InfoDb): return
printInfo(InfoDb[i])
return recursion(i + 1)
recursion(0)
def new_game():
guesses = []
correct_guesses = 0
question_num = 1
for key in questions:
print("-------------------------")
print(key)
for i in options[question_num-1]:
print(i)
guess = input("Enter (A, B, C, or D): ")
guess = guess.upper()
guesses.append(guess)
correct_guesses += check_answer(questions.get(key),guess)
question_num += 1
display_score(correct_guesses, guesses)
# -------------------------
def check_answer(answer, guess):
if answer == guess:
print("CORRECT!")
return 1
else:
print("WRONG!")
return 0
# -------------------------
def display_score(correct_guesses, guesses):
print("-------------------------")
print("RESULTS")
print("-------------------------")
print("Answers: ", end="")
for i in questions:
print(questions.get(i), end =" ")
print()
print("Guesses: ", end="")
for i in guesses:
print(i, end =" ")
print()
score = int((correct_guesses/len(questions))*100)
print("Your score is: "+str(score)+"%")
# -------------------------
def play_again():
response = input("Do you want to play again?: (yes or no): ")
response = response.upper()
if response == "YES":
return True
else:
return False
# -------------------------
questions = {
"What is the formula (value-mean)/stand deviation used for?: ": "A",
"What is the median of the following sequence of numbers 1,2,5,8,9?: ": "B",
"What is the standard deviation of the following sequence 5,5,15,15 ?: ": "C",
"What is the mean of the following sequence 2,4,6,10,20?: ": "A",
}
options = [["A. Z-score", "B. mean", "C. median", "D. IQR"],
["A. 2", "B. 5", "C. 8", "D. 6"],
["A. 10", "B. 15", "C. 5", "D. 0"],
["A. 8.4", "B. 10", "C. 7.6", "D. 9"]]
new_game()
while play_again():
new_game()
print("Bye!")