name = "Kalani Cabral-Omana"
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 Kalani Cabral-Omana <class 'str'>
age 16 <class 'int'>
score 100.0 <class 'float'>

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

person {'name': 'Kalani Cabral-Omana', 'age': 16, 'score': 100.0, 'langs': ['Python', 'JavaScript', 'Java']} <class 'dict'>
- person["name"] Kalani Cabral-Omana <class 'str'>

Shoe Dictionary

Shoes = []

# Append to List a Dictionary of key/values related to a person and cars
Shoes.append({
    "Shoe": "Nike",
    "Model": "Dunk",
    "Year": "2016",
    "Color": "Blue",
})


Shoes.append({
    "Shoe": "Vans",
    "Model": "Classic",
    "Year": "2020",
    "Color": "Black",
})

Shoes.append({
    "Shoe": "Converse",
    "Model": "High-Top",
    "Year": "2021",
    "Color": "Blck",
})

Shoes.append({
    "Shoe": "Nike",
    "Model": "Blazers",
    "Year": "2020",
    "Color": "White",
})

Shoes.append({
    "Shoe": "Adidas",
    "Model": "Yeezy",
    "Year": "2023",
    "Color": "White",
})

Shoes.append({
    "Shoe": "Adidas",
    "Model": "Yeezy",
    "Year": "2022",
    "Color": "Black",
})

Shoes.append({
    "Shoe": "Nike",
    "Model": "Trainers",
    "Year": "2021",
    "Color": "Red",
})
# Print the data structure
print(Shoes)
[{'Shoe': 'Nike', 'Model': 'Dunk', 'Year': '2016', 'Color': 'Blue'}, {'Shoe': 'Vans', 'Model': 'Classic', 'Year': '2020', 'Color': 'Black'}, {'Shoe': 'Converse', 'Model': 'High-Top', 'Year': '2021', 'Color': 'Blck'}, {'Shoe': 'Nike', 'Model': 'Blazers', 'Year': '2020', 'Color': 'White'}, {'Shoe': 'Adidas', 'Model': 'Yeezy', 'Year': '2023', 'Color': 'White'}, {'Shoe': 'Adidas', 'Model': 'Yeezy', 'Year': '2022', 'Color': 'Black'}, {'Shoe': 'Nike', 'Model': 'Trainers', 'Year': '2021', 'Color': 'Red'}]

Adding Records to the InfoDb

InfoDb = []

# Append to List a Dictionary of key/values related to a person and cars
InfoDb.append({
    "FirstName": "Kalani",
    "LastName": "Cabral-Omana",
    "DOB": "April 18",
    "Residence": "San Diego",
    "Email": "kcabralomana@gmail.com.com",
    "Owns_Shoes": ["Nike Dunks, Black Vans, Black Converse, Nike Blazers"]
})

# Partner
# Append to List a 2nd Dictionary of key/values
InfoDb.append({
    "FirstName": "Navan",
    "LastName": "Yatavelli",
    "DOB": "October 31",
    "Residence": "San Diego",
    "Email": "navany@gmail.com",
    "Owns_Shoes": ["White Yeezy, Yeezy Slides"]
})

# Print the data structure
print(InfoDb)
[{'FirstName': 'Kalani', 'LastName': 'Cabral-Omana', 'DOB': 'April 18', 'Residence': 'San Diego', 'Email': 'kcabralomana@gmail.com.com', 'Owns_Shoes': ['Nike Dunks, Black Vans, Black Converse, Nike Blazers']}, {'FirstName': 'Navan', 'LastName': 'Yatavelli', 'DOB': 'October 31', 'Residence': 'San Diego', 'Email': 'navany@gmail.com', 'Owns_Shoes': ['White Yeezy, Yeezy Slides']}]

Using Index in For Loop

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", "Shoes: ", end="")  # end="" make sure no return occurs
    print(", ".join(d_rec["Owns_Shoes"]))  # 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 i in range(len(InfoDb)):
        print_data(InfoDb[i])

for_loop()
For loop output

Kalani Cabral-Omana
	 Residence: San Diego
	 Birth Day: April 18
	 Shoes: Nike Dunks, Black Vans, Black Converse, Nike Blazers

Navan Yatavelli
	 Residence: San Diego
	 Birth Day: October 31
	 Shoes: White Yeezy, Yeezy Slides

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

Kalani Cabral-Omana
	 Residence: San Diego
	 Birth Day: April 18
	 Shoes: Nike Dunks, Black Vans, Black Converse, Nike Blazers

Navan Yatavelli
	 Residence: San Diego
	 Birth Day: October 31
	 Shoes: White Yeezy, Yeezy Slides

Recursion

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

Kalani Cabral-Omana
	 Residence: San Diego
	 Birth Day: April 18
	 Shoes: Nike Dunks, Black Vans, Black Converse, Nike Blazers

Navan Yatavelli
	 Residence: San Diego
	 Birth Day: October 31
	 Shoes: White Yeezy, Yeezy Slides

Reverse Order

list = ["Vans","Converse","Yeezy","Blazers","Slides","Trainers"] 
for i in list: 
    print(i[::-1])
    print(list[::-1])
snaV
['Trainers', 'Slides', 'Blazers', 'Yeezy', 'Converse', 'Vans']
esrevnoC
['Trainers', 'Slides', 'Blazers', 'Yeezy', 'Converse', 'Vans']
yzeeY
['Trainers', 'Slides', 'Blazers', 'Yeezy', 'Converse', 'Vans']
srezalB
['Trainers', 'Slides', 'Blazers', 'Yeezy', 'Converse', 'Vans']
sedilS
['Trainers', 'Slides', 'Blazers', 'Yeezy', 'Converse', 'Vans']
sreniarT
['Trainers', 'Slides', 'Blazers', 'Yeezy', 'Converse', 'Vans']

Quiz That Stores In a List of Dictionaries

def question_with_response(prompt):
    print("Question: " + prompt) 



word = " "
questions = 4 # number of questions
correct = 0


questions_answers = [{"What command is used to include other functions that were previously developed?" : "import", 
                     "What command is used to evaluate correct or incorrect response in this example?" : "if", 
                     "Each 'if' command contains an '_________' to determine a true or false condition?" : "expression",
                     "Variables for the values the function needs. Is passed as an argument when the function is called" : "parameters"}] # dictionary
# questions_answers.append = ({"What command is used to include other functions that were previously developed?" : "import", 
#                      "What command is used to evaluate correct or incorrect response in this example?" : "if", 
#                      "Each 'if' command contains an '_________' to determine a true or false condition?" : "expression",
#                      "Variables for the values the function needs. Is passed as an argument when the function is called" : "parameters"}) # dictionary

for i in questions_answers:
    for question, answer in i.items():
        question_with_response(question) # printing the questions
        word = input("Answer: ") # variable that connects to the user's input
        if word == answer:  # if the answer provided is correct
            print("You got it right!!")
            correct += 1
        else:  # if the answer provided is wrong
            print("Your answer was wrong")

print(str(correct) + "/" + str(questions)) # correct/len(questions_answers)
Question: What command is used to include other functions that were previously developed?
You got it right!!
Question: What command is used to evaluate correct or incorrect response in this example?
You got it right!!
Question: Each 'if' command contains an '_________' to determine a true or false condition?
You got it right!!
Question: Variables for the values the function needs. Is passed as an argument when the function is called
Your answer was wrong
3/4