+ 3

‘That’s Odd’ Python help

#receive user input and store in list ‘nums’ nums = list(map(int, input().split())) #store even numbers from nums evens = [x for x in nums if x % 2 == 0] #add together all the even numbers print(sum(evens)) Could anyone PLEASE tell me why this wouldn’t be working?? I cannot for the life of me figure out what I’m doing wrong... as far as I can tell the only output I’m getting is “0”

25th May 2020, 9:10 PM
Megan
Megan - avatar
14 Antworten
+ 5
num = int(input()) even = 0 value = 1 while value <=num: value += 1 x = int(input()) if x % 2 == 0: even += x print(even)
15th Jun 2020, 8:23 PM
John McCormack
John McCormack - avatar
+ 4
Each number is input on a new line not all on the same line.
25th May 2020, 9:17 PM
ChaoticDawg
ChaoticDawg - avatar
+ 4
lenth = int(input()) a = 0 total = 0 while a<lenth: i = int(input()) if i%2==0: total+=i a+=1 print(total) for explanation dm me no offense i can explain better there... cuzz comment box conversation is silly
10th Jun 2020, 9:01 PM
Taran Grover
Taran Grover - avatar
+ 2
ChaoticDawg so what parameter would i need to put inside split() for it to see ‘enter’ or ‘new line’ as the delimiter?
25th May 2020, 9:32 PM
Megan
Megan - avatar
+ 2
split takes all whitespace as delimiter. However, the input function goes always until the next newline only. So for this code, you have to enter all numbers in one line.
25th May 2020, 9:35 PM
HonFu
HonFu - avatar
+ 1
You need to loop to input N times
25th May 2020, 9:33 PM
ChaoticDawg
ChaoticDawg - avatar
0
num=int(input()) sum=0 for i in range(num): num=int(input()) if (num%2!=0): sum=sum+num print(sum) """" int sum = 0; for(int i=0;i<=num;i++) { if(num%2!=0) sum=sum+num; print(sum) } """"
18th Nov 2022, 7:24 PM
Anita chaubey
Anita chaubey - avatar
0
num=int(input()) sum=0 for i in range(num): num=int(input()) if (num%2!=0): sum=sum+num print(sum) """" int sum = 0; for(int i=0;i<=num;i++) { if(num%2!=0) sum=sum+num; print(sum) } """"
18th Nov 2022, 7:24 PM
Anita chaubey
Anita chaubey - avatar
0
num=int(input()) sum=0 for i in range(num): num=int(input()) if (num%2!=0): sum=sum+num print(sum) """" int sum = 0; for(int i=0;i<=num;i++) { if(num%2!=0) { sum=sum+num; print(sum) } } """" int sum = 0; int i= 0; while(num%2!=0) { sum=sum+num; i=i+1; print(sum); } """"
18th Nov 2022, 7:38 PM
Anita chaubey
Anita chaubey - avatar
0
num=int(input()) sum=0 for i in range(num): num=int(input()) if (num%2!=0): sum=sum+num print(sum) """" int sum = 0; for(int i=0;i<=num;i++) { if(num%2!=0) { sum=sum+num; print(sum) } } """" int sum = 0; int i= 0; while(num%2!=0) { sum=sum+num; i=i+1; print(sum); } """"
18th Nov 2022, 7:38 PM
Anita chaubey
Anita chaubey - avatar
0
num=int(input()) sum=0 for i in range(num): num=int(input()) if (num%2!=0): sum=sum+num print(sum) """" int sum = 0; for(int i=0;i<=num;i++) { if(num%2!=0) { sum=sum+num; print(sum) } } """" int sum = 0; int i= 0; while(num%2!=0) { sum=sum+num; i=i+1; print(sum); } """"
18th Nov 2022, 7:38 PM
Anita chaubey
Anita chaubey - avatar
0
num=int(input()) sum=0 for i in range(num): num=int(input()) if (num%2!=0): sum=sum+num print(sum) """" int sum = 0; for(int i=0;i<=num;i++) { if(num%2!=0) { sum=sum+num; print(sum) } } """" int sum = 0; int i= 0; while(num%2!=0) { sum=sum+num; i=i+1; print(sum); } """"
18th Nov 2022, 7:38 PM
Anita chaubey
Anita chaubey - avatar
0
nums=[] ans=0 range_of_nums=int(input()) while 1: try: nums.append(int(input())) except EOFError: break for i in range(range_of_nums): if nums[i]%2==0: ans+=nums[i] print(ans)
21st Mar 2023, 12:10 PM
Danil Ryaboshtanov