Python Lists
This post is regarding the Python lists assignment.
# # variable of type string
# print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
# name = "John Doe"
# print("name", name, type(name))
# print()
# # variable of type integer
# print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
# age = 18
# print("age", age, type(age))
# print()
# # variable of type float
# print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
# score = 90.0
# print("score", score, type(score))
# print()
# # variable of type list (many values in one variable)
# print("What is variable name/key?", "value?", "type?", "primitive or collection?")
# print("What is different about the list output?")
# langs = ["Python", "JavaScript", "Java", "Bash"]
# print("langs", langs, type(langs), "length", len(langs))
# print("- langs[3]", langs[3], type(langs[3]))
# print()
# # variable of type dictionary (a group of keys and values)
# print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
# print("What is different about the dictionary output?")
# person = {
# "name": name,
# "age": age,
# "score": score,
# "langs": langs
# }
# print("person", person, type(person), "length", len(person))
# print('- person["name"]', person["name"], type(person["name"]))
# # print function: given a dictionary of InfoDb content
# #d_rec is the dictionary
# #to access dictionary you use the key values and to access the List you use indexes
# 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)
# for_loop()
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({
"FoodName": "Pancakes",
"Price": "$7",
"Calories": "730",
"Ingredients": ["Eggs", "Milk", "Sugar", "Vanilla Extract", "Flour", "Butter Milk", "Baking soda"]
})
# Append to List a 2nd Dictionary of key/values
InfoDb.append({
"FoodName": "Vanilla sponge",
"Price": "$3",
"Calories": "180",
"Ingredients": ["Eggs", "Milk", "Sugar", "Vanilla Extract", "Flour"]
})
#append to List a 3rd Dictionary of key/values
InfoDb.append({
"FoodName": "French Toast",
"Price": "$6",
"Calories": "310",
"Ingredients": ["Eggs", "Milk", "Cinnamon", "Sugar", "Vanilla Extract"]
})
#append to List a 3rd Dictionary of key/values
InfoDb.append({
"FoodName": "Chocolate cake",
"Price": "$5",
"Calories": "230",
"Ingredients": ["Eggs", "Milk", "Cocoa Powder", "Sugar", "Vanilla Extract", "Flour"]
})
# Print the data structure
print(InfoDb[0])
price = InfoDb[0]["Price"]
calories = InfoDb[0]["Calories"]
ingredients = InfoDb[0]["Ingredients"]
def question_and_answer(prompt):
print("Question: " + prompt)
msg = input()
print("Answer: " + msg)
print(" ")
print(price)
print(" ")
print("Calories:" + calories)
print(" ")
print(ingredients)
question_and_answer("Please write your preference below:")