# 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"]))
name Akshat Parikh <class 'str'>
age 16 <class 'int'>
score 100.0 <class 'float'>

langs ['Python', 'JavaScript', 'Java'] <class 'list'>
- langs[0] Python <class 'str'>

person {'name': 'Akshat Parikh', 'age': 16, 'score': 100.0, 'langs': ['Python', 'JavaScript', 'Java']} <class 'dict'>
- person["name"] Akshat Parikh <class 'str'>
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)
[{'Car': 'Rolls Royce', 'Model': 'Wraith', 'Year': '2016', 'Engine': 'V12'}, {'Car': 'Mercedes Benz Maybach', 'Model': 'S580', 'Year': '2020', 'Engine': 'V10'}, {'Car': 'Mercedes G-Wagon', 'Model': 'G-Wagon', 'Year': '2021', 'Engine': 'V10'}, {'Car': 'Jeep', 'Model': 'Gladiator Rubicon', 'Year': '2020', 'Engine': 'V6'}, {'Car': 'Cadillac', 'Model': 'Escalade 600 Black', 'Year': '2023', 'Engine': 'V8'}, {'Car': 'Rivian', 'Model': 'R1S', 'Year': '2023', 'Engine': 'Electric'}, {'Car': 'Land Rover', 'Model': 'Range Rover', 'Year': '2021', 'Engine': 'V8'}]
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)
[{'FirstName': 'Akshat', 'LastName': 'Parikh', 'DOB': 'December 28', 'Residence': 'San Diego', 'Email': 'jmortensen@powayusd.com', 'Owns_Cars': ['Rolls Royce Culinan, Mercedes Maybach, Mercedes G-Wagon, Ashton Martin Vantage']}, {'FirstName': 'David', 'LastName': 'Vasilev', 'DOB': 'May 27', 'Residence': 'San Diego', 'Email': 'davidv42185@stu.powayusd.com', 'Owns_Cars': ['McLaren 720s, Ferrari 488']}]
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()
For loop output

Akshat Parikh
	 Residence: San Diego
	 Birth Day: December 28
	 Cars: Rolls Royce Culinan, Mercedes Maybach, Mercedes G-Wagon, Ashton Martin Vantage

David Vasilev
	 Residence: San Diego
	 Birth Day: May 27
	 Cars: McLaren 720s, Ferrari 488

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()
While loop output

Akshat Parikh
	 Residence: San Diego
	 Birth Day: December 28
	 Cars: Rolls Royce Culinan, Mercedes Maybach, Mercedes G-Wagon, Ashton Martin Vantage

David Vasilev
	 Residence: San Diego
	 Birth Day: May 27
	 Cars: McLaren 720s, Ferrari 488

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)
Recursive loop output

Akshat Parikh
	 Residence: San Diego
	 Birth Day: December 28
	 Cars: Rolls Royce Culinan, Mercedes Maybach, Mercedes G-Wagon, Ashton Martin Vantage

David Vasilev
	 Residence: San Diego
	 Birth Day: May 27
	 Cars: McLaren 720s, Ferrari 488

Python Cars Quiz

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()
Hello, akshat1228!
	 You will be asked 7 questions on cars.
Question: Whats the most expensive car in the world?
	 Mercedes Benz 300 SLR - $142,000,000 is correct!
Question: Which company owns Rolls Royce?
	 BMW is correct!
Question: What is the biggest electric car company?
	 Tesla is correct!
Question: What company owns Jaguar?
	 TATA Motors is correct!
Question: Whose the best F1 Racer?
	 Max Verstappen is correct!
Question: Who is the F1 G.O.A.T?
	 Lewis Hamilton is correct!
Question: What company owns Corvette?
	 GM is correct!
akshat1228 you scored 7/7!!
Here is a record of your quiz:
For loop output

Question 1: Mercedes Benz 300 SLR - $142,000,000
Question 2: BMW
Question 3: Tesla
Question 4: TATA Motors
Question 5: Max Verstappen