print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
name = "Qais Jamili"
print("name", name, type(name))

print()


# variable of type integer
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
age = 15
print("age", age, type(age))

print()

# variable of type float
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
score = 90.0
print("score", score, type(score))

print()

# variable of type list (many values in one variable)
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()

# 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 = {
    "Qais Jamili": name,
    "15": age,
    "90.0": score,
    "langs": langs
}
print("person", person, type(person), "length", len(person))
print('- person["name"]', person["name"], type(person["name"]))
What is the variable name/key? value? type? primitive or collection, why?
name Qais Jamili <class 'str'>

What is the variable name/key? value? type? primitive or collection, why?
age 15 <class 'int'>

What is the variable name/key? value? type? primitive or collection, why?
score 90.0 <class 'float'>

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'>

What is the variable name/key? value? type? primitive or collection, why?
What is different about the dictionary output?
person {'Qais Jamili': 'Qais Jamili', '15': 15, '90.0': 90.0, 'langs': ['Python', 'JavaScript', 'Java']} <class 'dict'> length 4
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/mnt/c/Users/qaisj/vscode/quissite/_notebooks/2022-09-12-Dictionary.ipynb Cell 2 in <cell line: 42>()
     <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/qaisj/vscode/quissite/_notebooks/2022-09-12-Dictionary.ipynb#X10sdnNjb2RlLXJlbW90ZQ%3D%3D?line=34'>35</a> person = {
     <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/qaisj/vscode/quissite/_notebooks/2022-09-12-Dictionary.ipynb#X10sdnNjb2RlLXJlbW90ZQ%3D%3D?line=35'>36</a>     "Qais Jamili": name,
     <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/qaisj/vscode/quissite/_notebooks/2022-09-12-Dictionary.ipynb#X10sdnNjb2RlLXJlbW90ZQ%3D%3D?line=36'>37</a>     "15": age,
     <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/qaisj/vscode/quissite/_notebooks/2022-09-12-Dictionary.ipynb#X10sdnNjb2RlLXJlbW90ZQ%3D%3D?line=37'>38</a>     "90.0": score,
     <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/qaisj/vscode/quissite/_notebooks/2022-09-12-Dictionary.ipynb#X10sdnNjb2RlLXJlbW90ZQ%3D%3D?line=38'>39</a>     "langs": langs
     <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/qaisj/vscode/quissite/_notebooks/2022-09-12-Dictionary.ipynb#X10sdnNjb2RlLXJlbW90ZQ%3D%3D?line=39'>40</a> }
     <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/qaisj/vscode/quissite/_notebooks/2022-09-12-Dictionary.ipynb#X10sdnNjb2RlLXJlbW90ZQ%3D%3D?line=40'>41</a> print("person", person, type(person), "length", len(person))
---> <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/qaisj/vscode/quissite/_notebooks/2022-09-12-Dictionary.ipynb#X10sdnNjb2RlLXJlbW90ZQ%3D%3D?line=41'>42</a> print('- person["name"]', person["name"], type(person["name"]))

KeyError: 'name'
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": "Qais",
    "LastName": "Jamili",
    "DOB": "January 19",
    "Residence": "San Diego",
    "Email": "qaisjamili22@gmail.com",
    "Owns_Cars":["4Runner"]
})



# Print the data structure
print(InfoDb)
[{'FirstName': 'Qais', 'LastName': 'Jamili', 'DOB': 'January 19', 'Residence': 'San Diego', 'Email': 'qaisjamili22@gmail.com', 'Owns_Cars': ['4Runner']}]
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)

for_loop()
For loop output

Qais Jamili
	 Residence: San Diego
	 Birth Day: January 19
	 Cars: 4Runner

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

Qais Jamili
	 Residence: San Diego
	 Birth Day: January 19
	 Cars: 4Runner

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

Qais Jamili
	 Residence: San Diego
	 Birth Day: January 19
	 Cars: 4Runner