Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # it's a way with using global vars without passing values as formal params(arguments) to functions
- # defining global vars for program
- grade_book = {}
- s_name = ""
- s_grade1 = 0
- s_grade2 = 0
- s_grade3 = 0
- def menu():
- return (input("would you like add new student? ").lower() in ["y", "yes"])
- def add_student():
- # this vars are global in local name scoope
- global s_name
- global s_grade1
- global s_grade2
- global s_grade3
- s_name = input("name of student: ")
- print(f"Enter grades for student: {s_name}")
- s_grade1 = int(input("grade 1: "))
- s_grade2 = int(input("grade 2: "))
- s_grade3 = int(input("grade 3: "))
- def disp_grade_book():
- # this vars are global in local name scoope
- global grade_book
- global s_name
- global s_grade1
- global s_grade2
- global s_grade3
- grade_book[s_name] = [s_grade1, s_grade2, s_grade3]
- for name, grades in grade_book.items():
- print(f"grades for student {name}: ")
- for grade in grades:
- print(grade)
- if menu():
- add_student()
- disp_grade_book()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement