Pass or Fail

Pass or Fail

In a university exam of engineering students on various subjects, certain number of students passed in certain  subjects and failed in certain subjects. Taking one student into consideration,  write a simple program in Python  by using appropriate Python sequence to count the number of subjects he has passed and failed in.  Score 50 and below is considered fail. 

Note:

  • If the no. of subjects is 0 or less display “Invalid no. of subjects” and terminate the program
  • if the mark is below 0 or above 100 , then display “Invalid mark” and terminate the program

Sample input 1:

Enter the no. of subjects: 8

Enter the marks:

60

55

34

90

50

25

49

89

Sample output 1:

No. of subjects passed: 4

No. of subjects failed: 4

Sample input 2:

Enter the no. of subjects: 0

Sample output 2:

Invalid no. of subjects

Sample input 3:

Enter the no. of subjects: 10

Enter the marks:

10

0

5

109

Sample output 3:

Invalid mark

Code :-

n=int(input("Enter the no. of subjects: "))
l=[]
f=0
p=0
if n>0:
    print("Enter the marks:")
    for i in range(n):
        i=int(input())
        if i>=0 and i<=100:
            l.append(i)
        else:
            print("Invalid mark")
            exit()
    for i in l:
        if i<=50:
            f=f+1
        else:
            p=p+1
    print("No. of subjects passed:",p)
    print("No. of subjects failed:",f)
else:
    print("Invalid no. of subjects")
            
            
    

Leave a Comment

Your email address will not be published. Required fields are marked *

x