Q. Write a program to store student names and their percentage in a dictionary and delete a particular student name from the dictionary. Also display the dictionary after deletion.
Answer =
dic = {} while True : nam = input("Enter name :- ") per = float(input("Enter percentage :- ")) dic[nam] = per a = input("Do you want to enter more records enter (Yes/ No) :- ") print() if a == "No" or a == "no": break clas = input("Enter name which you want to delete :- ") del dic[clas] print("Dictionary",dic)
Output :-
Enter name :- Path
Enter percentage :- 99.4
Do you want to enter more records enter (Yes/ No) :- yes
Enter name :- Walla
Enter percentage :- 85.2
Do you want to enter more records enter (Yes/ No) :- yes
Enter name :- Portal
Enter percentage :- 76.92
Do you want to enter more records enter (Yes/ No) :- No
Enter name which you want to delete :- Walla
Dictionary {'Path': 99.4, 'Portal': 76.92}
>>>
Enter percentage :- 99.4
Do you want to enter more records enter (Yes/ No) :- yes
Enter name :- Walla
Enter percentage :- 85.2
Do you want to enter more records enter (Yes/ No) :- yes
Enter name :- Portal
Enter percentage :- 76.92
Do you want to enter more records enter (Yes/ No) :- No
Enter name which you want to delete :- Walla
Dictionary {'Path': 99.4, 'Portal': 76.92}
>>>
name 'true' is not defined.
ReplyDeletePlease enter correct spelling. It is "True" not "true".
DeleteInstead of clas name will come.
ReplyDeleteI did not understand what you want to please comment again.
DeleteI wrote this in my exam but my teacher told me that it is wrong ....is my teacher right???
ReplyDeleteDon't worry she is wrong. You can run the program in front of your teacher and get the marks.
DeleteWhere is display
ReplyDeleteI didn't understand what you want to say please tell me again.
DeleteDisplay the output
ReplyDeleteOk, I have uploaded it.
Deletecan you explain using for loop........
ReplyDeletewe can not use for loop for infinite times.
Deletedo u have youtube channel in which u can explain in video?
ReplyDeletePortal Express
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )