import getpass
import sys

#While loop to check answers
def question_with_response(prompt, correct_answer):
    while True:
        print("Question: " + prompt)
        msg = input()
        if msg == correct_answer:
            print(correct_answer + " is correct!")
            return True
        else:
            print(msg + " is incorrect. Please try again.")

#Bank of Questions to pull from
questions = [
    ("What command is used to include other functions that were previously developed?", "import"),
    ("What command is used to evaluate correct or incorrect response in this example?", "if"),
    ("Each 'if' command contains an '_________' to determine a true or false condition?", "expression"),
    ("A list data type has the method _____", ".append(expression)")
]
#Sets quiz score to zero
correct = 0
#Main program script (what the user sees on the screen)
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(len(questions)) + " questions.")
question_with_response("Are you ready to take a test?", "yes")

#For loop iterates and calls question_with_response
for question, correct_answer in questions:
    if question_with_response(question, correct_answer):
        # Adds 1 point per correct answer.
        correct += 1

print(getpass.getuser() + " you scored " + str(correct) + "/" + str(len(questions)))

import getpass, sys

def question_with_response(prompt):
    print("Question: " + prompt)
    msg = input()
    return msg

questions = 3
correct = 0

print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
question_with_response("Are you ready to take a test?")

rsp = question_with_response("What command is used to include other functions that were previously developed?")
if rsp == "import":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

rsp = question_with_response("What command is used to evaluate correct or incorrect response in this example?")
if rsp == "if":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

rsp = question_with_response("Each 'if' command contains an '_________' to determine a true or false condition?")
if rsp == "expression":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")



print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
# 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": "John",
    "LastName": "Mortensen",
    "DOB": "October 21",
    "Residence": "San Diego",
    "Email": "jmortensen@powayusd.com",
    "Owns_Cars": ["2015-Fusion", "2011-Ranger", "2003-Excursion", "1997-F350", "1969-Cadillac"]
})

# Append to List a 2nd Dictionary of key/values
InfoDb.append({
    "FirstName": "Sunny",
    "LastName": "Naidu",
    "DOB": "August 2",
    "Residence": "Temecula",
    "Email": "snaidu@powayusd.com",
    "Owns_Cars": ["4Runner"]
})

# Append to List a 2nd Dictionary of key/values
InfoDb.append({
    "FirstName": "Shane",
    "LastName": "Lopez",
    "DOB": "February 27",
    "Residence": "San Diego",
    "Email": "???@powayusd.com",
    "Owns_Cars": ["2021-Insight"]
})

# Print the data structure
print(InfoDb)
# This jupyter cell has dependencies on one or more cells above

# print function: given a dictionary of InfoDb content
def print_data(d_rec):
    print(d_rec["FirstName"], 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()


# for loop algorithm iterates on length of InfoDb
def for_loop():
    print("For loop output\n")
    for record in InfoDb:
        print_data(record) # call to function

for_loop() # call to function