The output should contain N space-separated integers representing the number of people who played after the person and scored less than the person.
def smaller_scores(L:list, N:int):
s = [0 for i in range(N)]
for i in range(N-1):
for j in range(i+1,N):
if L[i] > L[j]:
s[i] += 1
print(*s)
while True:
try:
N = int(input())
L = list(map(int,input().split()))
if len(L) != N:
raise ValueError
except ValueError:
print('incorect input, try again')
continue
smaller_scores(L,N)
The above program throws an error:
N = int(input())
EOFError: EOF when reading a line
COuld you please help me to get an expected output?
def smaller_scores(L: list, N: int):
s = list(filter(lambda x: x < N, L))
s = s[:N]
if len(s) > 0:
print(*s)
else:
print('No scores')
while True:
try:
N = int(input())
L = list(map(int, input().split()))
if len(L) < N:
raise ValueError
except ValueError:
print('incorect input, try again')
continue
smaller_scores(L, N)
Comments
Leave a comment