InfoDb is a database that has information about students' grades, their names, and student id numbers within it. The final goal is to get an input from the user of the student ID, find it in the dictionary, and print the correct student's information.

InfoDb = []

# Append to List a Dictionary of key/values related student and grades
InfoDb.append({
    "Name": ["Sofia Kemuel"],
    "Student ID": ["1029"],
    "Math": ["88% B+"],
    "English": ["93% A-"],
    "History": ["95% A"],
    "Art": ["98% A+"],
    "Physical Education": ["89% B+"],
})
# Append to List a 2nd Dictionary of key/values
InfoDb.append({
    "Name": ["Jennifer Darcey"],
    "Student ID": ["2837"],
    "Math": ["77% C+"],
    "English": ["90% A-"],
    "History": ["91% A-"],
    "Art": ["100% A+"],
    "Physical Education": ["82% B-"],
})


# Print the data structure
print(InfoDb)
print()
[{'Name': ['Sofia Kemuel'], 'Student ID': ['1029'], 'Math': ['88% B+'], 'English': ['93% A-'], 'History': ['95% A'], 'Art': ['98% A+'], 'Physical Education': ['89% B+']}, {'Name': ['Jennifer Darcey'], 'Student ID': ['2837'], 'Math': ['77% C+'], 'English': ['90% A-'], 'History': ['91% A-'], 'Art': ['100% A+'], 'Physical Education': ['82% B-']}]

As you can see, the code cell above has just saved the information of students Sofia and Jennifer within the dictionaries.

def print_data(db):
    print(db["Name"])  
    print("\t", "Student ID:", db["Student ID"])  
    print("\t", "Math:", db["Math"]) 
    print("\t", "English:", db["English"])
    print("\t", "History:", db["History"])
    print("\t", "Art:", db["Art"])
    print("\t", "Physical Education:", db["Physical Education"])
    print()

# define function for_loop to print dictionaries
def for_loop():
    for record in InfoDb:
        print_data(record)

for_loop()
['Sofia Kemuel']
	 Student ID: ['1029']
	 Math: ['88% B+']
	 English: ['93% A-']
	 History: ['95% A']
	 Art: ['98% A+']
	 Physical Education: ['89% B+']

['Jennifer Darcey']
	 Student ID: ['2837']
	 Math: ['77% C+']
	 English: ['90% A-']
	 History: ['91% A-']
	 Art: ['100% A+']
	 Physical Education: ['82% B-']

Using a for loop, the code cell above finds the record within InfoDb and prints student information one by one for all students (2).

def while_loop():
    i = 0
    while i < len(InfoDb):
        record = InfoDb[i]
        print_data(record)
        i += 1
    return

while_loop()
['Sofia Kemuel']
	 Student ID: ['1029']
	 Math: ['88% B+']
	 English: ['93% A-']
	 History: ['95% A']
	 Art: ['98% A+']
	 Physical Education: ['89% B+']

['Jennifer Darcey']
	 Student ID: ['2837']
	 Math: ['77% C+']
	 English: ['90% A-']
	 History: ['91% A-']
	 Art: ['100% A+']
	 Physical Education: ['82% B-']

The code cell above executes a code using a while loop to print the contents of the dictionary. It loops comparing a value i to the length of the dictionary.

def recursive_loop(i):
    if i < len(InfoDb):
        record = InfoDb[i]
        print_data(record)
        recursive_loop(i + 1)
    return
    
recursive_loop(0)
['Sofia Kemuel']
	 Student ID: ['1029']
	 Math: ['88% B+']
	 English: ['93% A-']
	 History: ['95% A']
	 Art: ['98% A+']
	 Physical Education: ['89% B+']

['Jennifer Darcey']
	 Student ID: ['2837']
	 Math: ['77% C+']
	 English: ['90% A-']
	 History: ['91% A-']
	 Art: ['100% A+']
	 Physical Education: ['82% B-']

The code cell above prints the contents of the infodb dictionary using a recursive function (meaning the function itself is called within the loop)

input_id = input("Enter student ID: ")



# define function to find in InfoDb and print information corrsponding to certain ID 
def loop_with_input():
    for record in InfoDb:
        if search(record, input_id):
            print_data(record)

loop_with_input()
['Sofia Kemuel']
	 Student ID: ['1029']
	 Math: ['88% B+']
	 English: ['93% A-']
	 History: ['95% A']
	 Art: ['98% A+']
	 Physical Education: ['89% B+']

The code cell above takes the input from the user and assigns it to the variable "input_id". It uses a for loop and 'record' in InfoDb to loop betweeen all the student's data one by one. It checks whether input_id is in each student's data. If it is, it prints the student data.