Computer Science
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
n = int(input("Enter number of students: "))
data = {}
for i in range(n):
stu_name = input("Enter student name: ")
percentage = input("Enter percentage: ")
data[stu_name] = percentage
print("Student data:", data)
find = input("Enter a student name to delete: ")
if find in data:
del data[find]
print("Updated student data:", data)
else:
print("Student not found in the data.")
Output
Enter number of students: 4
Enter student name: Megha
Enter percentage: 98
Enter student name: Amit
Enter percentage: 88
Enter student name: Nitin
Enter percentage: 92
Enter student name: Amulya
Enter percentage: 79
Student data: {'Megha': '98', 'Amit': '88', 'Nitin': '92', 'Amulya': '79'}
Enter a student name to delete: Nitin
Updated student data: {'Megha': '98', 'Amit': '88', 'Amulya': '79'}
Related Questions
Write a program to input any values for two tuples. Print it, interchange it and then compare them.
Write a Python program to input 'n' classes and names of class teachers to store them in a dictionary and display the same. Also accept a particular class from the user and display the name of the class teacher of that class.
Write a Python program to input names of 'n' customers and their details like items bought, cost and phone number, etc., store them in a dictionary and display all the details in a tabular form.
Write a Python program to capitalize first and last letters of each word of a given string.