print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
name = "Tucker Golpariani"
print("name", name, type(name))
What is the variable name/key? value? type? primitive or collection, why?
name Tucker Golpariani <class 'str'>

Note 1

Here, a variable is defined, a name (name = “Tucker Golpariani”) for it to then be printed. It’s like a key.

print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
age = 16
print("age", age, type(age))
What is the variable name/key? value? type? primitive or collection, why?
age 16 <class 'int'>
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
score = 80.0
print("score", score, type(score))
What is the variable name/key? value? type? primitive or collection, why?
score 80.0 <class 'float'>
print("What is variable name/key?", "value?", "type?", "primitive or collection?")
print("What is different about the list output?")
langs = ["Python", "JavaScript", "Java"]
print("langs", langs, type(langs), "length", len(langs))
print("- langs[0]", langs[0], type(langs[0]))
print("- langs[1]", langs[1], type(langs[1]))
print("- langs[2]", langs[2], type(langs[2]))
What is variable name/key? value? type? primitive or collection?
What is different about the list output?
langs ['Python', 'JavaScript', 'Java'] <class 'list'> length 3
- langs[0] Python <class 'str'>
- langs[1] JavaScript <class 'str'>
- langs[2] Java <class 'str'>
# 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('- person["age"]', person["age"], type(person["age"]))
print('- person["score"]', person["score"], type(person["score"]))
print('- person["langs"]', person["langs"], type(person["langs"]))
What is the variable name/key? value? type? primitive or collection, why?
What is different about the dictionary output?
person {'name': 'Tucker Golpariani', 'age': 16, 'score': 80.0, 'langs': ['Python', 'JavaScript', 'Java']} <class 'dict'> length 4
- person["name"] Tucker Golpariani <class 'str'>
- person["age"] 16 <class 'int'>
- person["score"] 80.0 <class 'float'>
- person["langs"] ['Python', 'JavaScript', 'Java'] <class 'list'>

Note 2

Above, it is seen that various variables are defined for them to then be printed. Types of these variables consist of strings, integers, and floats.

# Define an empty List called InfoDb
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({
    "FirstName": "Tucker",
    "LastName": "Golpariani",
    "DOB": "July 19",
    "Residence": "San Diego",
    "Email": "tuckerg09806@stu.powayusd.com",
    "Owns_Cars": ["We don't have personal cars",]
})

# Append to List a 2nd Dictionary of key/values
InfoDb.append({
    "FirstName": "William",
    "LastName": "Lee",
    "DOB": "May 3",
    "Residence": "San Diego",
    "Email": "williaml61525@stu.powayusd.com",
    "Owns_Cars": ["We don't have personal cars"]
})

# Print the data structure
print(InfoDb)
[{'FirstName': 'Tucker', 'LastName': 'Golpariani', 'DOB': 'July 19', 'Residence': 'San Diego', 'Email': 'tuckerg09806@stu.powayusd.com', 'Owns_Cars': ["We don't have personal cars"]}, {'FirstName': 'William', 'LastName': 'Lee', 'DOB': 'May 3', 'Residence': 'San Diego', 'Email': 'williaml61525@stu.powayusd.com', 'Owns_Cars': ["We don't have personal cars"]}]
# This jupyter cell has dependencies on one or more cells above

# print function: given a dictionary of InfoDb content
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) # call to function

for_loop() # call to function
For loop output

Tucker Golpariani
	 Residence: San Diego
	 Birth Day: July 19
	 Cars: We don't have personal cars

William Lee
	 Residence: San Diego
	 Birth Day: May 3
	 Cars: We don't have personal cars
# This jupyter cell has dependencies on one or more cells above

# while loop algorithm contains an initial n and an index incrementing statement (n += 1)
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

Tucker Golpariani
	 Residence: San Diego
	 Birth Day: July 19
	 Cars: We don't have personal cars

William Lee
	 Residence: San Diego
	 Birth Day: May 3
	 Cars: We don't have personal cars
# This jupyter cell has dependencies on one or more cells above

# recursion algorithm loops incrementing on each call (n + 1) until exit condition is met
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

Tucker Golpariani
	 Residence: San Diego
	 Birth Day: July 19
	 Cars: We don't have personal cars

William Lee
	 Residence: San Diego
	 Birth Day: May 3
	 Cars: We don't have personal cars