# variable of type string
name = "Akshat Parikh"
print("name", name, type(name))
# variable of type integer
age = 16
print("age", age, type(age))
# variable of type float
score = 100.0
print("score", score, type(score))
print()
# variable of type list (many values in one variable)
langs = ["Python", "JavaScript", "Java"]
print("langs", langs, type(langs))
print("- langs[0]", langs[0], type(langs[0]))
print()
# variable of type dictionary (a group of keys and values)
person = {
"name": name,
"age": age,
"score": score,
"langs": langs
}
print("person", person, type(person))
print('- person["name"]', person["name"], type(person["name"]))
Cars = []
# Append to List a Dictionary of key/values related to a person and cars
Cars.append({
"Car": "Rolls Royce",
"Model": "Wraith",
"Year": "2016",
"Engine": "V12",
})
Cars.append({
"Car": "Mercedes Benz Maybach",
"Model": "S580",
"Year": "2020",
"Engine": "V10",
})
Cars.append({
"Car": "Mercedes G-Wagon",
"Model": "G-Wagon",
"Year": "2021",
"Engine": "V10",
})
Cars.append({
"Car": "Jeep",
"Model": "Gladiator Rubicon",
"Year": "2020",
"Engine": "V6",
})
Cars.append({
"Car": "Cadillac",
"Model": "Escalade 600 Black",
"Year": "2023",
"Engine": "V8",
})
Cars.append({
"Car": "Rivian",
"Model": "R1S",
"Year": "2023",
"Engine": "Electric",
})
Cars.append({
"Car": "Land Rover",
"Model": "Range Rover",
"Year": "2021",
"Engine": "V8",
})
# Print the data structure
print(Cars)
InfoDb = []
# Append to List a Dictionary of key/values related to a person and cars
InfoDb.append({
"FirstName": "Akshat",
"LastName": "Parikh",
"DOB": "December 28",
"Residence": "San Diego",
"Email": "akshat1228@gmail.com",
"Owns_Cars": ["Rolls Royce Culinan, Mercedes Maybach, Mercedes G-Wagon, Ashton Martin Vantage"]
})
# Partner
# Append to List a 2nd Dictionary of key/values
InfoDb.append({
"FirstName": "David",
"LastName": "Vasilev",
"DOB": "May 27",
"Residence": "San Diego",
"Email": "davidv42185@stu.powayusd.com",
"Owns_Cars": ["McLaren 720s, Ferrari 488"]
})
# 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", "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 iterates on length of InfoDb
def for_loop():
print("For loop output\n")
for record in InfoDb:
print_data(record)
for_loop()
def while_loop():
print("While loop output\n")
i = 0
while i < len(InfoDb):
record = InfoDb[i]
print_data(record)
i += 1
return
while_loop()
def recursive_loop(i):
if i < len(InfoDb):
record = InfoDb[i]
print_data(record)
recursive_loop(i + 1)
return
print("Recursive loop output\n")
recursive_loop(0)
import getpass, sys
questions = 7
correct = 0
print('Hello, ' + getpass.getuser() + '!')
print("\t", "You will be asked " + str(questions) + " questions on cars.")
def question_and_answer(prompt, answer):
print("Question: " + prompt)
rsp = input()
if rsp == answer :
print("\t", rsp + " is correct!")
global correct
correct += 1
else:
print ("\t", rsp + " is incorrect!")
return rsp
Question_1 = question_and_answer("Whats the most expensive car in the world?", "Mercedes Benz 300 SLR - $142,000,000")
Question_2 = question_and_answer("Which company owns Rolls Royce?", "BMW")
Question_3 = question_and_answer("What is the biggest electric car company?", "Tesla")
Question_4 = question_and_answer("What company owns Jaguar?", "TATA Motors")
Question_5 = question_and_answer("Whose the best F1 Racer?", "Max Verstappen")
Question_6 = question_and_answer("Who is the F1 G.O.A.T?", "Lewis Hamilton")
Question_7 = question_and_answer("What company owns Corvette?", "GM")
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions) + "!!")
Quiz = []
Quiz.append({
"Q_1": Question_1,
"Q_2": Question_2,
"Q_3": Question_3,
"Q_4": Question_4,
"Q_5": Question_5,
"Q_6": Question_6,
"Q_7": Question_7
})
#List Implementation
def print_data(d_rec):
print("Question 1:", d_rec["Q_1"])
print("Question 2:", d_rec["Q_2"])
print("Question 3:", d_rec["Q_3"])
print("Question 4:", d_rec["Q_4"])
print("Question 5:", d_rec["Q_5"], end="")
print()
print("Here is a record of your quiz:")
def for_loop():
print("For loop output\n")
for record in Quiz:
print_data(record)
for_loop()