Home > Software engineering >  searching for numbers greater than 60 in a list
searching for numbers greater than 60 in a list

Time:03-03

i cant seem to get the second for loop to work correctly, nor the third. ive tried removing them and switching a few things around in the last if statement but its only gotten worse.

scores = []
passed = 0
passing = 60

tests = int(input("enter the number of tests:"))
for x in range (0,tests):
    marks = int(input("enter the number of marks:"))
    scores.append(marks)
for z in range (0,tests):
    if any(scores > passing for y in len(scores)):
        passed = passed   1

print("")
print(passed, "have passed")

CodePudding user response:

I think you are a loop short.

You ask for the number of tests, and for each test, you ask for the number of scores — but you never ask for the scores themselves.

CodePudding user response:

At the second for loop, you can get each score by specifying each score on the list with scores[z] on the condition. not only scores

if any(**scores[z]** > passing for y in len(scores)):

all code :

scores = []
passed = 0
passing = 60

tests = int(input("enter the number of tests:"))
for x in range(0, tests):
    marks = int(input("enter the number of marks:"))
    scores.append(marks)
for z in range(0, tests):
    if any(scores[z] > passing for y in scores):
        passed = passed   1

print("")
print(passed, "have passed")

output sample :

enter the number of tests:5
enter the number of marks:75
enter the number of marks:50
enter the number of marks:35
enter the number of marks:85
enter the number of marks:95

3 have passed

Hope it helps you.

  • Related