Title
langs = ["Python", "JavaScript", "Java", "Bash", "C", "C++"]
print("langs", langs, type(langs), "length", len(langs))
print("- langs[0]", langs[2], type(langs[2]))
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
name = "Shruthi Damodar"
print("name", name, type(name))
print()
# variable of type integer
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
age = 17
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", "Bash", "C", "C++"]
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 = {
"name": name,
"age": age,
"score": score,
"langs": langs
}
print("person", person, type(person), "length", len(person))
print('- person["name"]', person["name"], type(person["name"]))
mylist = {1, 2, 3, 4}
print("mylist", mylist, type(mylist), "length", len(mylist))
InfoDb = []
InfoDb.append({
"FirstName": "Shruthi",
"LastName": "Damodar",
"DOB": "October 29",
"Residence": "San Diego",
"Email": "damodar.shruthi@gmail.com",
"TVShow": "Puppy Dog Pals",
"Music": "Country Music"
})
print(InfoDb)
def print_data(d_rec):
print(d_rec["FirstName"], d_rec["LastName"])
print("\t", "Residence:", d_rec["Residence"])
print("\t", "Birth Day:", d_rec["DOB"])
print("\t", "TVShow:", d_rec["TVShow"])
print("\t", "Music:", d_rec["Music"])
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)