- 1

How should I change this?

I want this code to know In the first line m which represents the number of numbers and m in the next lines is the numbers. from functools import reduce print(reduce(int.__add__,map(lambda x:int(x)**2,filter(lambda x:int(x)>0, input().split()))))

16th May 2022, 9:00 AM
Mahdiye Raeisi
2 Antworten
+ 2
Mahdiye Raeisi , it is difficult to understand what you wanted to achieve. it looks like the shown code is truncated and therefore incomplete. -> please make a sample of input data, also provide the expected output thanks!
16th May 2022, 9:47 AM
Lothar
Lothar - avatar
0
it's computing the sum of squares for numbers greater than 0. you said: " I want this code to know In the first line m which represents the number of numbers and m in the next lines is the numbers. " Why would you need the number of numbers? you are not programming with C. The code does not need to know the number of numbers. It is not using it. You just directly input your numbers and it will work on that. It is strange that you can write a code this cryptic and not know what it is doing.🤔 1 2 3 submit 14 result (1**2 + 2**2 + 3**2)
16th May 2022, 9:45 AM
Bob_Li
Bob_Li - avatar