Introduction

In this lesson, we will explore the various ways to create loops in Python. Loops are essential for repetitive tasks and are a fundamental concept in programming. We will cover different types of loops, advanced loop techniques, and how to work with lists and dictionaries using loops.

For Loops

  • Used to iterate over a sequence (such as a list, tuple, string, or range)
  • Executes a block of code for each item in the sequence
# APCSP Pseudo-Code: Iterating Over a List of Fruits

fruits  ["apple", "banana", "cherry"]

FOR EACH fruit IN fruits:
    DISPLAY fruit
END FOR



# Example 1: Simple for loop
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)
apple
banana
cherry

While Loops

  • Used to execute a block of code as long as a condition is true
# APCSP Pseudo-Code: Using a While Loop to Count and Display Numbers


i  1


WHILE i  5:
    DISPLAY i
    i  i + 1
END WHILE
# Example 2: Simple while loop
i = 1
while i <= 5:
    print(i)
    i += 1
1
2
3
4
5

Looping with Lists and Dictionaries

  • Used to iterate through the elements of lists and dictionaries
# APCSP Pseudo-Code: Loop Through a List

numbers  [1, 2, 3, 4]
FOR EACH num IN numbers:
    DISPLAY num
END FOR

# APCSP Pseudo-Code: Loop Through a Dictionary
person  {"name": "aashray", "age": 15, "city": "San Diego"}
FOR EACH key, value IN person:
    DISPLAY key, ":", value
END FOR

# Example 3: Loop through a list
numbers = [1, 2, 3, 4]
for num in numbers:
    print(num)

# Example 4: Loop through a dictionary
person = {"name": "aashray", "age": 15, "city": "San Diego"}
for key, value in person.items():
    print(key, ":", value)

1
2
3
4
name : aashray
age : 15
city : San Diego

Popcorn Hack 1

  • Use a loop to get X amount of inputs. Then use a loop to find the type of each value.

  • Extra Challenge: If an input is a number, make the corresponding value in the dictionary a number.

sample_dict = {1: 'yes', 2: 5, 3:6.7}

# Code goes here

for item in sample_dict:
    add = input('Enter new value: ')
    try:
        number = int(add)
        sample_dict[sample_dict.length() + 1] = add
    except:
        sample_dict[add] = 'string'
              

Looping with Index Variable

You can use the range function to create a loop with an index variable.

# APCSP Pseudo-Code: Loop Through a List Using Index

lst  [4, 6, 7, 2]
FOR i IN RANGE(LENGTH(lst)):
    DISPLAY "Index: " + STRING(i)
    DISPLAY "Element: " + STRING(GET_ELEMENT(lst, i))
END FOR
# Example 5: Loop with an index variable

lst = [4, 6, 7, 2]

for i in range(len(lst)): # Loop for the number of elements in the list
    print('Index: ' + str(i)) # Print the index
    print('Element: ' + str(lst[i])) # Print the element
Index: 0
Element: 4
Index: 1
Element: 6
Index: 2
Element: 7
Index: 3
Element: 2

Nested If Statements

You can nest conditional statements inside a for loop to execute different code based on conditions.

# APCSP Pseudo-Code: For Loop with Nested If Statements

numbers  [1, 2, 3, 4, 5]
FOR EACH num IN numbers:
    IF num MOD 2 EQUALS 0:
        DISPLAY num, "is even"
    ELSE:
        DISPLAY num, "is odd"
    END IF
END FOR

# Example 6: For loop with nested if statements
numbers = [1, 2, 3, 4, 5]
for num in numbers:
    if num % 2 == 0:
        print(num, "is even")
    else:
        print(num, "is odd")
1 is odd
2 is even
3 is odd
4 is even
5 is odd

Popcorn Hack 2

  • Use the input() function to append a range of integers from a list

  • Use a nested if statement to only print numbers in the list that are evenly divisble by 3

nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

#Code goes here

start = int(input('Enter Start Value: '))
end = int(input('Enter End Value: '))

newnum = []

for i in range(end - 1):
    newnum.append(nums[i + start])

for num in newnum:
    if True:
        if num % 3 == 0:
            print(num)
3
6
9
12

Try/Except

  • Using a try and except block inside a loop can handle errors gracefully.

  • Very useful for production code, even in frontend webapps

    • Ex: Giving an error page instead of dumping critical information on the webpage
# APCSP Pseudo-Code: Handling Errors in a For Loop

numbers  [1, 2, "three", 4, 0, "five"]
FOR EACH item IN numbers:
    TRY:
        DISPLAY 10 / item
    CATCH ZeroDivisionError:
        DISPLAY "Division by zero"
    CATCH TypeError:
        DISPLAY "Type error"
    END TRY
END FOR

numbers = [1, 2, "three", 4, 0, "five"]

for item in numbers:
    try:
        print(10 / item)
    except ZeroDivisionError: #Type of error: Dividing by Zero
        print("Division by zero")
    except TypeError: #Type of error: Dividing by something that isn't a number
        print("Type error")
10.0
5.0
Type error
2.5
Division by zero
Type error

Popcorn Hack 3

  • Create a for loop that uses a try and except statement for an AttributeError
  • Use integers and a list to create scenarios where the loop will either print something expected or print an error message
  • CHALLENGE: Try using the math module for this error
import math
numbers = [-1, 0, 1, 2, 3]

i = 10

try:
    i.append(4)
except AttributeError:
    print('AttributeError happened')

for num in numbers:
    try:
        print(num / (num - 1))
        print(math.log(num + 5, num))
    except Exception as error:
        print(error)
AttributeError happened
0.5
math domain error
-0.0
math domain error
division by zero
2.0
2.807354922057604
1.5
1.892789260714372

Continue and Break

  • Continue statement skips the current iteration
  • Break statement exits the loop prematurely
# APCSP Pseudo-Code: For Loop with Continue and Break

numbers  [1, 2, 3, 4, 5]
FOR EACH num IN numbers:
 
    IF num EQUALS 3:
        CONTINUE
    IF num EQUALS 5:
        BREAK 
    DISPLAY num
END FOR

# Example 8: For loop with continue and break
numbers = [1, 2, 3, 4, 5]
for num in numbers:
    if num == 3:
        continue  # Skip the number 3
    if num == 5:
        break  # Exit the loop when 5 is encountered
    print(num)
1
2
4

Nested For Loops

  • You can also put for loops within for loops
  • Allows for looping an exponential amount of times
# APCSP Pseudo-Code: Nested Loops for Group Names

groups  [["advik", "aashray"], ["akhil", "srijan"]]

FOR EACH pair IN groups:
    FOR EACH person IN pair:
        DISPLAY person + " is cool"
    END FOR
    DISPLAY pair[0] + " and " + pair[1] + " love to code code code"
END FOR

groups = [['advik', 'aashray'], ['akhil', 'srijan']]

for pair in groups:
    for person in pair:
        print(person + ' is cool')
    print(pair[0] + ' and ' + pair[1] + ' love to code code code')
advik is cool
aashray is cool
advik and aashray love to code code code
akhil is cool
srijan is cool
akhil and srijan love to code code code

(OPTIONAL) Popcorn Hack 4

  • Create a nested for loop that iterates over a dictionary that has:
    • A name for each key
    • A list for each value containing stuff like age, grade, etc.
  • Break/continue if certain conditions are met
  • Have fun! If you want to, relate it to a theme!
people = {}

# Code here

Iteration via Recursion

  • A technique where a function calls itself
  • Can be used to recreate loops until a certain condition is met
# APCSP Pseudo-Code: Recursion for Factorial Calculation

FUNCTION factorial(n):
    IF n EQUALS 0:
        RETURN 1
    ELSE IF n LESS THAN 0:
        RETURN "undefined"
    ELSE IF TYPEOF(n) EQUALS "float":
        RETURN "not solvable without gamma function"
    ELSE:
        RETURN n TIMES factorial(n - 1)
    END IF
END FUNCTION

result  CALL factorial(5)
DISPLAY "Factorial of 5 is", result

# Example 9: Recursion for factorial calculation
def factorial(n):
    if n == 0: #Conditions to stop the recursion
        return 1 # 0! is 1
    elif n < 0:
        return "undefined" # Undefined for negative numbers 
    elif isinstance(n, float):
        return "not solvable without gamma function" # Only accept integers
    else:
        return n * factorial(n - 1) #Function calling itself

result = factorial(5)
print("Factorial of 5 is", result)
Factorial of 5 is 120

Homework

  • Add student names w/ grades to a dictionary until the user doesn’t want more students
    • Prompt for user input for all of these
  • Use a nested if/else statement in a for loop
    • Get the highest score in the dictionary
    • Add all students who passed into a new list (add student names, not their scores)
  • Bonus: Use a try/except for any scores that aren’t integers
students = {}

print('Welcome to Student Database!')
finished = False
while not finished:
    print('A: Update Student List\nB: Update Student Grades\nC: Get Student Grade\nD: Get Highest Grade\nE: Get Passing Students')
    usercannotread = True
    while usercannotread:
        option = input('What would you like to do?: ')
        if option not in ['A', 'B', 'C', 'D', 'E']:
            print('ERROR, there is no option ' + option)
        else:
            usercannotread = False
    if option == 'A':
        done = False
        while not done:
            student = input('Enter Student Name: ')
            gradeIsValid = False
            while not gradeIsValid:
                grade = input('Enter Student Grade: ')
                grade = int(grade)
                gradeIsValid = True
            students[student] = int(grade)
            doneyet = input('Are you done yet? [y/n]: ')
            if doneyet == 'y':
                done = True
        print('New Student List: ' + str(students))
    elif option == 'B':
        done = False
        while not done:
            student = input('Enter Student Name: ')
            gradeIsValid = False  
            grade = input('Enter Student Grade: ')
            grade = int(grade)
            gradeIsValid = True
            if not(student in students):
                print('Error: Student is not already in database. Adding Student')
            students[student] = int(grade)
            doneyet = input('Are you done yet? [y/n]: ')
            if doneyet == 'y':
                done = True
        print('New Student List: ' + str(students))
    elif option == 'C':
        student = input('Enter Student Name: ')
        print(student + '\'s grade is ' + str(students[student]))
    elif option == 'D':
        highestStudent = ''
        highestStudentScore = 0
        for student in students:
            if students[student] > highestStudentScore:
                highestStudentScore = students[student]
                highestStudent = student
        print('The highest scoring student is ' + highestStudent + '. S/he has a grade of ' + str(highestStudentScore) + '.')
    elif option == 'E':
        passgrade = 70
        change = input('The default passing score is 70%. Would you like to change it? [y/n]: ')
        if change == 'y':
            passIsValid = False
            while not passIsValid:   
                newpass = input('Enter passing grade (integer, number only): ')
                passgrade = int(newpass)
                passIsValid = True
        passed = {}
        passed_list = []
        failed = {}
        failed_list = []
        for student in students:
            if students[student] >= passgrade:
                passed[student] = students[student]
                ## useless arrays but required in question, dictionaries are more useful
                passed_list.append(student)
            else:
                failed[student] = students[student]
                failed_list.append(student)
        print('The following students passed: ')
        print(passed)
        print('The following students failed: ')
        print(failed)
    finishedyet = input('Do you want to exit or keep working? [1 - exit, 2 - keep working]: ')
    if finishedyet == '1':
        finished = True
    print('-------------------------------------------------------------')
print('Thank you for using Student Database!')
Welcome to Student Database!
A: Update Student List
B: Update Student Grades
C: Get Student Grade
D: Get Highest Grade
E: Get Passing Students
New Student List: {'John': 90}
-------------------------------------------------------------
A: Update Student List
B: Update Student Grades
C: Get Student Grade
D: Get Highest Grade
E: Get Passing Students
John's grade is 90
-------------------------------------------------------------
A: Update Student List
B: Update Student Grades
C: Get Student Grade
D: Get Highest Grade
E: Get Passing Students
New Student List: {'John': 91, 'Toby': 85, 'Hop': 97}
-------------------------------------------------------------
A: Update Student List
B: Update Student Grades
C: Get Student Grade
D: Get Highest Grade
E: Get Passing Students
The highest scoring student is Hop. S/he has a grade of 97.
-------------------------------------------------------------
A: Update Student List
B: Update Student Grades
C: Get Student Grade
D: Get Highest Grade
E: Get Passing Students
The following students passed: 
{'John': 91, 'Hop': 97}
The following students failed: 
{'Toby': 85}
-------------------------------------------------------------
Thank you for using Student Database!
(lambda _Y: (lambda students: [print('Welcome to Student Database!'), (lambda finished: (lambda change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread: (lambda _loop1: _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread))(_Y(lambda _loop1: (lambda change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread: ([print('A: Update Student List\nB: Update Student Grades\nC: Get Student Grade\nD: Get Highest Grade\nE: Get Passing Students'), (lambda usercannotread: (lambda option, usercannotread: (lambda _loop8: _loop8(option, usercannotread))(_Y(lambda _loop8: (lambda option, usercannotread: ((lambda option: ([print(('ERROR, there is no option ' + option)), _loop8(option, usercannotread)][-1] if (option not in ['A', 'B', 'C', 'D', 'E']) else (lambda usercannotread: _loop8(option, usercannotread))(False)))(input('What would you like to do?: '))) if usercannotread else ((lambda done: (lambda done, doneyet, grade, gradeIsValid, student: (lambda _loop2: _loop2(done, doneyet, grade, gradeIsValid, student))(_Y(lambda _loop2: (lambda done, doneyet, grade, gradeIsValid, student: ((lambda student: (lambda gradeIsValid: (lambda grade, gradeIsValid: (lambda _loop3: _loop3(grade, gradeIsValid))(_Y(lambda _loop3: (lambda grade, gradeIsValid: ((lambda grade: (lambda grade: (lambda gradeIsValid: _loop3(grade, gradeIsValid))(True))(int(grade)))(input('Enter Student Grade: '))) if not gradeIsValid else [(lambda doneyet: ((lambda done: _loop2(done, doneyet, grade, gradeIsValid, student))(True) if (doneyet == 'y') else _loop2(done, doneyet, grade, gradeIsValid, student)))(input('Are you done yet? [y/n]: ')) for students[student] in [int(grade)]][0]))))(grade if "grade" in dir() else None, gradeIsValid if "gradeIsValid" in dir() else None))(False))(input('Enter Student Name: '))) if not done else [print(('New Student List: ' + str(students))), (lambda finishedyet: ((lambda finished: [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1])(True) if (finishedyet == '1') else [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1]))(input('Do you want to exit or keep working? [1 - exit, 2 - keep working]: '))][-1]))))(done if "done" in dir() else None, doneyet if "doneyet" in dir() else None, grade if "grade" in dir() else None, gradeIsValid if "gradeIsValid" in dir() else None, student if "student" in dir() else None))(False) if (option == 'A') else ((lambda done: (lambda done, doneyet, grade, gradeIsValid, student: (lambda _loop4: _loop4(done, doneyet, grade, gradeIsValid, student))(_Y(lambda _loop4: (lambda done, doneyet, grade, gradeIsValid, student: ((lambda student: (lambda gradeIsValid: (lambda grade: (lambda grade: (lambda gradeIsValid: ([print('Error: Student is not already in database. Adding Student'), [(lambda doneyet: ((lambda done: _loop4(done, doneyet, grade, gradeIsValid, student))(True) if (doneyet == 'y') else _loop4(done, doneyet, grade, gradeIsValid, student)))(input('Are you done yet? [y/n]: ')) for students[student] in [int(grade)]][0]][-1] if not ((student in students)) else [(lambda doneyet: ((lambda done: _loop4(done, doneyet, grade, gradeIsValid, student))(True) if (doneyet == 'y') else _loop4(done, doneyet, grade, gradeIsValid, student)))(input('Are you done yet? [y/n]: ')) for students[student] in [int(grade)]][0]))(True))(int(grade)))(input('Enter Student Grade: ')))(False))(input('Enter Student Name: '))) if not done else [print(('New Student List: ' + str(students))), (lambda finishedyet: ((lambda finished: [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1])(True) if (finishedyet == '1') else [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1]))(input('Do you want to exit or keep working? [1 - exit, 2 - keep working]: '))][-1]))))(done if "done" in dir() else None, doneyet if "doneyet" in dir() else None, grade if "grade" in dir() else None, gradeIsValid if "gradeIsValid" in dir() else None, student if "student" in dir() else None))(False) if (option == 'B') else ((lambda student: [print(((student + "'s grade is ") + str(students[student]))), (lambda finishedyet: ((lambda finished: [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1])(True) if (finishedyet == '1') else [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1]))(input('Do you want to exit or keep working? [1 - exit, 2 - keep working]: '))][-1])(input('Enter Student Name: ')) if (option == 'C') else ((lambda highestStudent: (lambda highestStudentScore: (lambda _term5, _items5: (lambda _targ5: (lambda _targ5, highestStudent, highestStudentScore, student: (lambda _loop5: _loop5(_targ5, highestStudent, highestStudentScore, student))(_Y(lambda _loop5: (lambda _targ5, highestStudent, highestStudentScore, student: ((lambda student: ((lambda highestStudentScore: (lambda highestStudent: (lambda _targ5: _loop5(_targ5, highestStudent, highestStudentScore, student))(next(_items5, _term5)))(student))(students[student]) if (students[student] > highestStudentScore) else (lambda _targ5: _loop5(_targ5, highestStudent, highestStudentScore, student))(next(_items5, _term5))))(_targ5)) if (_targ5 is not _term5) else [print((((('The highest scoring student is ' + highestStudent) + '. S/he has a grade of ') + str(highestStudentScore)) + '.')), (lambda finishedyet: ((lambda finished: [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1])(True) if (finishedyet == '1') else [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1]))(input('Do you want to exit or keep working? [1 - exit, 2 - keep working]: '))][-1]))))(_targ5 if "_targ5" in dir() else None, highestStudent if "highestStudent" in dir() else None, highestStudentScore if "highestStudentScore" in dir() else None, student if "student" in dir() else None))(next(_items5, _term5)))([], iter(students)))(0))('') if (option == 'D') else ((lambda passgrade: (lambda change: ((lambda passIsValid: (lambda newpass, passIsValid, passgrade: (lambda _loop7: _loop7(newpass, passIsValid, passgrade))(_Y(lambda _loop7: (lambda newpass, passIsValid, passgrade: ((lambda newpass: (lambda passgrade: (lambda passIsValid: _loop7(newpass, passIsValid, passgrade))(True))(int(newpass)))(input('Enter passing grade (integer, number only): '))) if not passIsValid else (lambda passed: (lambda passed_list: (lambda failed: (lambda failed_list: (lambda _term6, _items6: (lambda _targ6: (lambda _targ6, student: (lambda _loop6: _loop6(_targ6, student))(_Y(lambda _loop6: (lambda _targ6, student: ((lambda student: ([[passed_list.append(student), (lambda _targ6: _loop6(_targ6, student))(next(_items6, _term6))][-1] for passed[student] in [students[student]]][0] if (students[student] >= passgrade) else [[failed_list.append(student), (lambda _targ6: _loop6(_targ6, student))(next(_items6, _term6))][-1] for failed[student] in [students[student]]][0]))(_targ6)) if (_targ6 is not _term6) else [print('The following students passed: '), [print(passed), [print('The following students failed: '), [print(failed), (lambda finishedyet: ((lambda finished: [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1])(True) if (finishedyet == '1') else [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1]))(input('Do you want to exit or keep working? [1 - exit, 2 - keep working]: '))][-1]][-1]][-1]][-1]))))(_targ6 if "_targ6" in dir() else None, student if "student" in dir() else None))(next(_items6, _term6)))([], iter(students)))([]))({}))([]))({})))))(newpass if "newpass" in dir() else None, passIsValid if "passIsValid" in dir() else None, passgrade if "passgrade" in dir() else None))(False) if (change == 'y') else (lambda passed: (lambda passed_list: (lambda failed: (lambda failed_list: (lambda _term6, _items6: (lambda _targ6: (lambda _targ6, student: (lambda _loop6: _loop6(_targ6, student))(_Y(lambda _loop6: (lambda _targ6, student: ((lambda student: ([[passed_list.append(student), (lambda _targ6: _loop6(_targ6, student))(next(_items6, _term6))][-1] for passed[student] in [students[student]]][0] if (students[student] >= passgrade) else [[failed_list.append(student), (lambda _targ6: _loop6(_targ6, student))(next(_items6, _term6))][-1] for failed[student] in [students[student]]][0]))(_targ6)) if (_targ6 is not _term6) else [print('The following students passed: '), [print(passed), [print('The following students failed: '), [print(failed), (lambda finishedyet: ((lambda finished: [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1])(True) if (finishedyet == '1') else [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1]))(input('Do you want to exit or keep working? [1 - exit, 2 - keep working]: '))][-1]][-1]][-1]][-1]))))(_targ6 if "_targ6" in dir() else None, student if "student" in dir() else None))(next(_items6, _term6)))([], iter(students)))([]))({}))([]))({})))(input('The default passing score is 70%. Would you like to change it? [y/n]: ')))(70) if (option == 'E') else (lambda finishedyet: ((lambda finished: [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1])(True) if (finishedyet == '1') else [print('-------------------------------------------------------------'), _loop1(change, done, doneyet, failed, failed_list, finished, finishedyet, grade, gradeIsValid, highestStudent, highestStudentScore, newpass, option, passIsValid, passed, passed_list, passgrade, student, usercannotread)][-1]))(input('Do you want to exit or keep working? [1 - exit, 2 - keep working]: ')))))))))))(option if "option" in dir() else None, usercannotread if "usercannotread" in dir() else None))(True)][-1]) if not finished else print('Thank you for using Student Database!')))))(change if "change" in dir() else None, done if "done" in dir() else None, doneyet if "doneyet" in dir() else None, failed if "failed" in dir() else None, failed_list if "failed_list" in dir() else None, finished if "finished" in dir() else None, finishedyet if "finishedyet" in dir() else None, grade if "grade" in dir() else None, gradeIsValid if "gradeIsValid" in dir() else None, highestStudent if "highestStudent" in dir() else None, highestStudentScore if "highestStudentScore" in dir() else None, newpass if "newpass" in dir() else None, option if "option" in dir() else None, passIsValid if "passIsValid" in dir() else None, passed if "passed" in dir() else None, passed_list if "passed_list" in dir() else None, passgrade if "passgrade" in dir() else None, student if "student" in dir() else None, usercannotread if "usercannotread" in dir() else None))(False)][-1])({}))((lambda f: (lambda x: x(x))(lambda y: f(lambda *args: y(y)(*args)))))
Welcome to Student Database!
A: Update Student List
B: Update Student Grades
C: Get Student Grade
D: Get Highest Grade
E: Get Passing Students
New Student List: {'john': 90}
-------------------------------------------------------------
A: Update Student List
B: Update Student Grades
C: Get Student Grade
D: Get Highest Grade
E: Get Passing Students
john's grade is 90
-------------------------------------------------------------
Thank you for using Student Database!