Python program to create a dictionary with the roll number, name and marks of n students in a class and display the names of students who have marks above 75 | Computer Science 083 class XII

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

Solution : 

Also Check 

1.Create a binary file with name and roll number. Search for a given roll number and display the name, if not found display appropriate message -Pracrtical 083 CS XII 

2.Read a text file and display the number of vowels/ consonants/ uppercase/ lowercase characters and other than character and digit in the file

Source Code

n = int(input("How many Students?"))
stu = {}
for i in range(1, n+1):
    print("Enter details of Student", (i))
    rollno= int(input("Roll number :"))
    name = input("Name :")
    marks = float(input("Marks :"))
    d = {"Roll_no" : rollno, "Name": name, "Marks": marks}
    key = "Stu" + str(i)
    stu[key] = d
print("Students with marks > 75 are:")
for i in range(1, n+1):
        key = "Stu" + str(i)
        if stu[key]["Marks"] >= 75:
            print(stu[key])

Output

Sample Output:

How many Students?3 Enter details of Student 1 Roll number :01 Name :Raja Marks :57 Enter details of Student 2 Roll number :02 Name :Sanjay Marks :78 Enter details of Student 3 Roll number :03 Name :Devi Marks :79 Students with marks > 75 are: {'Roll_no': 2, 'Name': 'Sanjay', 'Marks': 78.0} {'Roll_no': 3, 'Name': 'Devi', 'Marks': 79.0} >>>

Post a Comment

If you any doubts, Please let me know

Previous Post Next Post