Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Construct a python program to read the three subject’s marks secured by n students during an examination. If a student secured less than 50 in any subject, the student is failed in that subject. Count the number of students who failed in each subject and the total number of students who failed in at least one subject.

Sample Workout as given below:

Input:

S1 = {'m1': 50, 'm2': 40, 'm3':75}

S2 = {'m2': 49, 'm3': 35, 'm4':54}

S3 = {'m1': 77, 'm2': 84, 'm4':51}

Output:

{'m1': 0, 'm2': 2, 'm3': 1, 'm4': 0}

2

What I have tried:

n=int(input())
L1=[]
noc=int(input())#no.of.courses
for i in range(1,n+1):
    for i in range(1,noc+1):
        Course=str(input())
        Mark=int(input())
        t=(Course,Mark)
        L1.append(t)
    dict1=dict(L1)
print(dict1)
for Course,Mark in dict1.items():
    if Mark<50:
        a=[Course]
print(a)
Posted
Updated 21-Nov-21 3:58am
Comments
Richard MacCutchan 21-Nov-21 9:38am    
What is your question?

1 solution

Read the question again, and pay attention to the detail of the requirement.
There are two things you have to do:
1) Count the number of students who failed in each subject: this means looking at the data for each subject and counting failed students.
2) Count the number of students who have at least one failed subject: this means looking at the data for each student.

Think about how you would do it manually, and work it out on paper - that should show you a "quick way" of doing it which you can then start to computerise.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900