Answer to Question #217147 in Python for Latha

Question #217147

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?


1
Expert's answer
2021-07-14T13:06:50-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS