Write a program to input roll numbers and their names of students of your class and store them in the dictionary as the key-value pair. Perform the following operations on the dictionary:
a) Display the Roll numbers and name for all students.
b) Add a new key-value pair in this dictionary and display the modified dictionary
c) Delete a particular student's record from the dictionary
d) Modify the name of an existing students.

Source Code

student = {}

print('Enter student details') 
while True:
    roll_number = int(input('Enter your 6 digit roll number: '))
    if roll_number in student:
        print('Roll Number Already Exists')
    else:
        name = input('Enter name: ')
        student[roll_number] = name
        print('Record added')
    ans = input('Do you want to continue(y/n)? ')
    if ans in 'nN':
        break

#######################################################
# a) Display the Roll numbers and name for all students
#######################################################

print('\nRoll Number','Name')
for roll_number in student:
    print(roll_number,'\t\t',student[roll_number])

#############################################################
# b) Add a new key-value pair in this dictionary and display 
#############################################################

print('\nEnter a new record ')
roll_number = int(input('Enter your 6 digit roll number: '))
if roll_number in student:
    print('Roll Number Already Exists')
else:
    name = input('Enter name: ')
    student[roll_number] = name
    print('Record added\n')

for roll_number in student:
    print(roll_number,'\t',student[roll_number])
    
#############################################################
# c) Delete a particular student's record from the dictionary
#############################################################

print('\nDelete a record ')
roll_number = int(input('Enter roll number: '))
if roll_number in student:
    del student[roll_number]
    print('Record deleted')
else:
    print('Record not found')

#############################################
# d) Modify the name of an existing students.
#############################################

print('\nModify a record')
roll_number = int(input('Enter new 6 digit roll number: '))

if roll_number in student:
    name=input('Modify name ')
    student[roll_number] = name
    print('Record updated')
else:
    print('Record not found')

Output

Enter student details
Enter your 6 digit roll number: 123456
Enter name: Deepak
Record added
Do you want to continue(y/n)? y
Enter your 6 digit roll number: 123457
Enter name: Nisha
Record added
Do you want to continue(y/n)? n

Roll Number Name
123456 Deepak
123457 Nisha

Enter a new record
Enter your 6 digit roll number: 123458
Enter name: Irfan
Record added

123456 Deepak
123457 Nisha
123458 Irfan

Delete a record
Enter roll number: 123457
Record deleted

Modify a record
Enter new 6 digit roll number: 123456
Modify name Imran
Record updated