+ 2
My code does not add up as in value but it rather adds up as strings
name =(input()).split() n = "" for i in name: if (int(i)%2==0): n += i print(n)
4 Respostas
+ 4
Because in n+=i
i is string not int
+ 4
Kwasi Anash,
additional to the posts already given, i want point to 3 things (there is nothing wrong, only to mention it):
(1) It is not necessary to split input to a list, you can iterate also over a string.
(2) (input()) does not need to be enclosed by parenthesis
(3) As i suppose that the input should be a number, it would be a good idea to mention what user should enter. It is also a bit confusing if a variable is named "name", but will contain a number.
+ 1
Do you want to count even digits?
int(i) only creates an int of i for that one line. i itself will remain a string.
This change should work:
name =(input()).split()
n = ""
for i in name:
i = int(i)
if (i%2==0):
n += i
print(n)