Python Lists and dictionaires Post
- InfoDb
- For Loops and Index
- Outputting in Reverse Order
- Other list methods
- Adding to a Dictionary
- Python Quiz
InfoDb = []
# 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"]
})
InfoDb.append({
"FirstName": "Ryan",
"LastName": "Hakimipour",
"DOB": "June 15",
"Residence": "San Diego",
"Email": "hakimipourryan@gmail.com",
"Owns_Cars": ["None"]
})
InfoDb.append({
"FirstName": "Soham",
"LastName": "Kamat",
"DOB": "March 9",
"Residence": "San Diego",
"Email": "sohamk10039@stu.powayusd.com",
"Owns_Cars": ["None"]
})
# Print the data structure
print(InfoDb)
Food = ["Burger", "Hot Dog", "Fries", "Pizza", "Goldfish", "Donut", "M&M", "Beef Kebab", "Chicken Kebab", "Burrito", "Tacos", "Chicken Sandwich"]
for i in Food:
print(i)
def is_palindrome(prompt):
print(prompt[::-1])
print(prompt)
return prompt[::-1] == prompt
word = input("Enter a word: ")
if is_palindrome(word.lower()) is True:
print("{0} is a palindrome!".format(word))
else:
print("The provided word is not a palindrome.")
Dangerous_Animals = ["Box Jellyfish", "African CAPE BuFfalo", "BLAck MambA", "Blue-RINGED octopus"]
Dangerous_Animals.append("Cone SnAIl")
for i in range(len(Dangerous_Animals)):
Dangerous_Animals[i] = Dangerous_Animals[i].lower()
print(Dangerous_Animals)
My_Dict = {
"Absence": "The lack or unavailability of something or someone.",
"Approval": "Having a positive opinion of something or someone.",
"Answer": "The response or receipt to a phone call, question, or letter.",
"Attention": "Noticing or recognizing something of interest.",
"Amount": "A mass or a collection of something.",
"Borrow": "To take something with the intention of returning it after a period of time.",
"Baffle": "An event or thing that is a mystery and confuses.",
"Ban": "An act that is prohibited by social pressure or law.",
"Cars": "Four-wheeled vehicles used for traveling.",
}
print(My_Dict)
My_Dict["Care"] = "extra responsibility and attention." #Added new key and value into dictionary
print(My_Dict)
My_Dict["Chip"] = input() # Added new value with input
print(My_Dict)
def Python_Quiz(prompt):
global word
print ("Question: " + prompt)
word = input()
return word
questions_number = 5
correct_answer = 0
print("Hello, you will be asked " + str(questions_number) + " short questions")
My_Quiz = [{
"What is the answer to this math problem: What does 45x7=": "315",
"What is the most popular religion in the world?": "Christianity",
"What is the capital of the U.S?": "Washington D.C.",
"How many kg is in 5g?": "0.005 kg",
"How many mm are in 1 km?": "1000000 mm",
}]
# My_Quiz.append({
# "What is the answer to this math problem: What does 45x7=": "315",
# "What is the most popular religion in the world?": "Christianity",
# "What is the capital of the U.S?": "Washington D.C.",
# "How many kg is in 5g?": "0.005 kg",
# "How many mm are in 1 km?": "1000000 mm",
# })
for dict in My_Quiz:
for questions, answers in dict.items():
Python_Quiz(questions)
if word == answers:
print("Answer is correct")
correct_answer += 1
else:
print("Answer is incorrect")
print("You scored " + str(correct_answer) + "/" + str(questions_number))