Wednesday, 17 December 2025

77 - Write a program in Python that repeatedly asks the user to input Student's Name and Class and store it in a dictionary D, whose keys are Student's Name and values are Student's Class. Then display the dictionary

Write a program in Python that repeatedly asks the user to input Student's Name and Class and store it in a dictionary D, whose keys are Student's Name and values are Student's Class. Then display the dictionary


D = {}

while True:

    name = input("Enter Student's Name: ")

    student_class = input("Enter Student's Class: ")


    D[name] = student_class


    choice = input("Do you want to add another student? (yes/no): ")

    if choice.lower() == "no":

        break

print("Student Dictionary:")

print(D)



Output:


Enter Student's Name: Amit

Enter Student's Class: 11

Do you want to add another student? (yes/no): yes

Enter Student's Name: Sumit

Enter Student's Class: 10

Do you want to add another student? (yes/no): yes

Enter Student's Name: Mohit

Enter Student's Class: 12

Do you want to add another student? (yes/no): yes

Enter Student's Name: Rohit

Enter Student's Class: 11

Do you want to add another student? (yes/no): no

Student Dictionary:

{'Amit': '11', 'Sumit': '10', 'Mohit': '12', 'Rohit': '11'} 

No comments:

Post a Comment