!!PYTHON PROGRAMMING ONLY!! Write a program that keeps a dictionary in which bot
ID: 3837248 • Letter: #
Question
!!PYTHON PROGRAMMING ONLY!!
Write a program that keeps a dictionary in which both keys and values are strings – names of students and their course grades. Your program should prompt the user with a menu consisting of the following options:
ECE-203 Programming for Engineers Homework Week 7 (50 Points) Write a program that keeps a dictionary in which both keys and values are strings names of students and their course grades. Your program should prompt the user with a menu consisting of the following options Selec t an option. [1] Add Student Grade [2] Remove Student Grade C3] Modify Student Grade [4] Display All Student Grades Enter selection If the user enters option 1 as shown below, the program shall behave as shown Select an option: [1] Add Student Grade [2] Remove student Grade [3] Modify Student Grade C4] Display All Student Grades Enter selection 1 Add Student Enter Name Joe Enter Grade B+ Student Successfully Added! Select an option C1 Add Student Grade [2] Remove Student Grade C3] Modify Student Grade C4 Display All Student Grades Enter selectionExplanation / Answer
Please run it in python 3+
d={}
def add():
nm=str(input("Enter Name: "))
gr=str(input("Enter grade: "))
d[nm]=gr
print("Added!")
def remove():
nm=str(input("Enter Name to remove: "))
if(nm in d):
del d[nm]
print("Removed!")
else:
print("Data not found")
def modify():
nm=str(input("Enter Name to modify: "))
if(nm in d):
gr=str(input("Enter new grade: "))
d[nm]=gr
print("Modified!")
else:
print("Name not found")
def disp():
for data in d:
print (data+": "+d[data])
def main():
while(1):
print("Select an option: ")
print(" 1. Add student grade")
print(" 2. Remove student grade")
print(" 3. Modify student grade")
print(" 4. Display all student grades")
print(" 5. Exit")
ch=int(input(""))
if(ch==1):
add()
elif(ch==2):
remove()
elif(ch==3):
modify()
elif(ch==4):
disp()
else:
break
main()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.