+ 2
Pls what is wrong with this code
For 'That's odd' challenge a = input().split() b = '' for x in a: if int(x) % 2 == 0: b += '+' + x c = eval(b) print(c)
12 Respostas
+ 6
Abdulhameed
Print value of variable <b> before you send it to eval(). Once you do that, you will understand what the problem isđ
+ 6
Abdulhameed I just fixed: eval, str+int, len(b)==0
+ 3
It is working on my windows IDE and on sololearn playground
+ 3
Ipang
Thank you
I understand nowđ
+ 2
M.d Nasif
Your code worked, Thanks
But I don't understand why mine did not work can you explain to me
Maybe I did not get the question correctly
+ 2
Thanks guys
I was able to solve
But can anyone explain to me why mine did not work
+ 2
Why people are suggesting alternative solutions lol !
When you input something like
40 40 and even 45 40 , that works fine ,since b isn't empty when evalutes but when input is something like 45 45 then b is just an empty string which isn't a valid python expression and so you get the error ,now you can google more about what python expressions are considered valid by eval function!
+ 1
The error it is showing is
Line 6
c = eval(b)
+ 1
here is my solution, hope it will help.
https://code.sololearn.com/czrrnkkXuLY3/?ref=app
+ 1
Addulhameed
b += '+' + x
char can't be added to char
b is char variable
'+' is char leteral
x is also char variable
not considered as valid operands for + operator.
DHANANJAY PATEL
0
Here is my solution
n = int(input())
l = [int(input()) for i in range(n)]
print(sum(list(filter(lambda x: x % 2 == 0, l))))