Basic L/D

name = "Mani T"
print("name", name, type(name))

age = 17
print("age", age, type(age))

score = 100.0
print("score", score, type(score))

print()

langs = ["Python", "Bash", "HTML"]
print("langs", langs, type(langs))
print("- langs[0]", langs[0], type(langs[0]))

print()

person = {
    "name": name,       # keys and values
    "age": age,
    "score": score,
    "langs": langs
}
print("person", person, type(person))
print('- person["name"]', person["name"], type(person["name"]))
name Mani T <class 'str'>
age 17 <class 'int'>
score 100.0 <class 'float'>

langs ['Python', 'Bash', 'HTML'] <class 'list'>
- langs[0] Python <class 'str'>

person {'name': 'Mani T', 'age': 17, 'score': 100.0, 'langs': ['Python', 'Bash', 'HTML']} <class 'dict'>
- person["name"] Mani T <class 'str'>

Complex L/D

InfoDb = []

InfoDb.append({         #introduces the data
    "FirstName": "Mani",
    "LastName": "Taleban",
    "DOB": "May 8",
    "Residence": "Somewhere",
    "SE": "moeint56403@stu.powayusd.com",
    "PE": "tmanimasih@gmail.com",
    "School": "Del Norte High School",
    "FM": "Whiplash",
    "FB": "Radiohead"
    
})

print(InfoDb)

def print_data(d_rec):
    print(d_rec["FirstName"], d_rec["LastName"])            # comma = space
    print("\t", "Residence:", d_rec["Residence"])       # \t = tab indent
    print("\t", "Birth Day:", d_rec["DOB"])
    print("\t", "School Email:", d_rec["SE"])
    print("\t", "Personal Email:", d_rec["PE"])
    print("\t", "School:", d_rec["School"])
    print("\t", "Favorite Movie:", d_rec["FM"])
    print("\t", "Favorite Band:", d_rec["FB"])
    print()


def for_loop():         # for loop
    print("For loop output\n")
    for record in InfoDb:
        print_data(record)

for_loop()
[{'FirstName': 'Mani', 'LastName': 'Taleban', 'DOB': 'May 8', 'Residence': 'Somewhere', 'SE': 'moeint56403@stu.powayusd.com', 'PE': 'tmanimasih@gmail.com', 'School': 'Del Norte High School', 'FM': 'Whiplash', 'FB': 'Radiohead'}]
For loop output

Mani Taleban
	 Residence: Somewhere
	 Birth Day: May 8
	 School Email: moeint56403@stu.powayusd.com
	 Personal Email: tmanimasih@gmail.com
	 School: Del Norte High School
	 Favorite Movie: Whiplash
	 Favorite Band: Radiohead

For Loop with an Index

InfoDb = []

InfoDb.append({
    "FirstName": "Mani",
    "LastName": "Taleban",
    "DOB": "May 8",
    "Residence": "Somewhere",
    "SE": "moeint56403@stu.powayusd.com",
    "PE": "tmanimasih@gmail.com",
    "School": "Del Norte High School",
    "FM": "Whiplash",
    "FB": "Radiohead"
    
})

print(InfoDb)
    
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()
[{'FirstName': 'Mani', 'LastName': 'Taleban', 'DOB': 'May 8', 'Residence': 'Somewhere', 'SE': 'moeint56403@stu.powayusd.com', 'PE': 'tmanimasih@gmail.com', 'School': 'Del Norte High School', 'FM': 'Whiplash', 'FB': 'Radiohead'}]
While loop output

Mani Taleban
	 Residence: Somewhere
	 Birth Day: May 8
	 School Email: moeint56403@stu.powayusd.com
	 Personal Email: tmanimasih@gmail.com
	 School: Del Norte High School
	 Favorite Movie: Whiplash
	 Favorite Band: Radiohead

InfoDb based Quiz

import getpass ,sys

def question_and_answer(prompt, answer):        # question and answer function 
    print("Question: " + prompt)
    msg = input()
    print("Answer: " + msg)
    
    if answer == msg.lower():           # this conditional determines the answers
        print(":)")
        global correct
        correct += 1
    else:
        print (":(")

questions = 5
correct = 0

Q1 = question_and_answer("What should I listen to right now?", "music")
Q2 = question_and_answer("When was I born?", "may 8")
Q3 = question_and_answer("Why was I born?", "idk")
Q4 = question_and_answer("Who plays Fletcher in Whiplash?", "jk simmons")
Q5 = question_and_answer("How's it going?", "eh")

Questions = {           # infoDb
    "Q1": Q1,
    "Q2": Q2,
    "Q3": Q3,
    "Q4": Q4,
    "Q5": Q5
}

print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
Question: What should I listen to right now?
Answer: music
:)
Question: When was I born?
Answer: may 8
:)
Question: Why was I born?
Answer: idk
:)
Question: Who plays Fletcher in Whiplash?
Answer: jk simmons
:)
Question: How's it going?
Answer: eh
:)
manimani you scored 5/5