81.1k views
5 votes
Address the FIXME comments. Move the respective code from the while-loop to the created function. The add_grade function has already been created.# FIXME: Create add_grade functiondef add_grade(student_grades):print('Entering grade. \\')name, grade = input(grade_prompt).split()student_grades[name] = grade# FIXME: Create delete_name function# FIXME: Create print_grades functionstudent_grades = {} # Create an empty dictgrade_prompt = "Enter name and grade (Ex. 'Bob A+'):\\"delete_prompt = "Enter name to delete:\\"menu_prompt = ("1. Add/modify student grade\\""2. Delete student grade\\""3. Print student grades\\""4. Quit\\\\")command = input(menu_prompt).lower().strip()while command != '4': # Exit when user enters '4'if command == '1':add_grade(student_grades)elif command == '2':# FIXME: Only call delete_name() hereprint('Deleting grade.\\')name = input(delete_prompt)del student_grades[name]elif command == '3':# FIXME: Only call print_grades() hereprint('Printing grades.\\') for name, grade in student_grades.items(): print(name, 'has a', grade) else: print('Unrecognized command.\\') command = input().lower().strip()

1 Answer

5 votes

Answer:

The Python code is given below with appropriate comments

Step-by-step explanation:

# FIXME: Create add_grade function

def add_grade(student_grades):

print('Entering grade. \\')

name, grade = input(grade_prompt).split()

student_grades[name] = grade

# FIXME: Create delete_name function

def delete_name(student_grades):

print('Deleting grade.\\')

name = input(delete_prompt)

del student_grades[name]

# FIXME: Create print_grades function

def print_grades(student_grades):

print('Printing grades.\\')

for name, grade in student_grades.items():

print(name, 'has a', grade)

student_grades = {} # Create an empty dict

grade_prompt = "Enter name and grade (Ex. 'Bob A+'):\\"

delete_prompt = "Enter name to delete:\\"

menu_prompt = ("1. Add/modify student grade\\"

"2. Delete student grade\\"

"3. Print student grades\\"

"4. Quit\\\\")

command = input(menu_prompt).lower().strip()

while command != '4': # Exit when user enters '4'

if command == '1':

add_grade(student_grades)

elif command == '2':

# FIXME: Only call delete_name() here

delete_name(student_grades)

elif command == '3':

# FIXME: Only call print_grades() here

print_grades(student_grades)

else:

print('Unrecognized command.\\')

command = input().lower().strip()

User Chuck M
by
5.0k points