Wednesday, 14 February 2024

Class 11 CS Practical - 40


40 - Write a program in Python to create a dictionary with the roll number, name and marks of n students of a class and display the name of students who have marks above 75.



n=int(input("Enter the number of students: "))

D={}

RN=[]

Name=[]

Marks=[]

for i in range(0,n):

    roll_no = int(input("Enter the roll number of the student: "))

    name=input("Enter the name of the student: ")

    marks=int(input("Enter the marks of the student: "))

    RN.append(roll_no)

    Name.append(name)

    Marks.append(marks)

D["Roll Number"]=RN

D["Name"]=Name

D["Marks"]=Marks

print("Dictionary of all students is: ",D)

print("Name of students who have marks above 75: ")

for i in range(0,n):

    if D["Marks"][i]>=75:

        print(D["Name"][i])




Output:

Enter the number of students: 5

Enter the roll number of the student: 1

Enter the name of the student: Ram

Enter the marks of the student: 78

Enter the roll number of the student: 2

Enter the name of the student: Raj

Enter the marks of the student: 48

Enter the roll number of the student: 3

Enter the name of the student: Sam

Enter the marks of the student: 79

Enter the roll number of the student: 4

Enter the name of the student: John

Enter the marks of the student: 84

Enter the roll number of the student: 5

Enter the name of the student: Amit

Enter the marks of the student: 67

Dictionary of all students is:  {'Roll Number': [1, 2, 3, 4, 5], 'Name': ['Ram', 'Raj', 'Sam', 'John', 'Amit'], 'Marks': [78, 48, 79, 84, 67]}

Name of students who have marks above 75:

Ram

Sam

John


No comments:

Post a Comment