Lists and Dictionary
questions = [
"What is your first name?",
"How Old are you?",
"What is your favorite food?",
"What is your favorite color?",
"What is your favorite place?",
"who are your friends",
]
print(questions)
print("What is your first name?")
name = "Big Man Nathan"
print(name)
print("How old are you?")
age = "16"
print(age)
# variable of type integer
print("What is your favorite Food")
food = "Pizza"
print(food)
print("How old are you?")
color = "Hot pink"
print(color)
# variable of type float
print("What is your favoirte place")
place = "Europe"
print(place)
# variable of type list (many values in one variable)
print("Who are your friends")
friends = "The leader of the friend group, Gene, Caleb"
print(friends)
# variable of type dictionary (a group of keys and values)
print("Is this you?")
person = {
"Your Name": name,
"Your Age": age,
"Favorite Food": food,
"Favorite Place": place,
"Your Friends": friends
}
print(person)
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": "Caleb",
"LastName": "Navarro",
"age": "16",
"DOB": "April 14",
"Residence": "San Diego",
"Email": "caleb.evan.navarro@gmail.com",
"Owns_Cars": ["Bugatti La Voiture Noire", "Audi A4"]
})
# Append to List a 2nd Dictionary of key/values
InfoDb.append({
"FirstName": "Billy",
"LastName": "Bob",
"age": "21",
"DOB": "December 21",
"Residence": "Europe",
"Email": "bigboybilly@gmail.com",
"Owns_Cars": ["Tesla"]
})
InfoDb.append({
"FirstName": "Nathan",
"LastName": "Capule",
"age": "16",
"DOB": "July 8",
"Residence": "Star Killer Base",
"Email": "plrttapotty@gmail.com",
"Owns_Cars": ["2019 Lamborghini Huracan Performante, Gerald R. Ford-class aircraft carrier, Starship"]
})
# Print the data structure
print(InfoDb)
def print_data(d_rec):
print(d_rec["FirstName"], d_rec["LastName"]) # using comma puts space between values
print("\t", "age:", d_rec["age"])
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)
for_loop()
import getpass, sys
questions = 3
correct = 0
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
def question_and_answer(prompt):
print("Question: " + prompt)
msg = input()
print("Answer: " + msg)
question_and_answer("How has your day been today?")
question_and_answer("Do you have friends?")
question_and_answer("Do you like ice cream")
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
question_and_answer("Are you ready for some questions?")
rsp = question_with_response("what is 10+6?")
if rsp == "16":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("What many tacos should you eat a day?")
if rsp == "42,069":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("From 1 to 10 how hot is toby?")
if rsp == "69":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))