+ 1
How can I make this code print the square of each even numbers in the list ?
""" Use a list comprehension to square each even number in the input""" values=input("Enter the values:") x=[i for i in values.split(",") if int(i)%2!=0 i*i] print((",").join(x))
4 Answers
+ 1
x=[i*i for i in values.split(",") if int(i)%2==0]
[ Edit: the title says "even", the body says "odd". Anyway, the change should be simple enough :) ]
+ 1
There's one more change, much more important - notice the "i*i" at the beginning.
0
oh yeah, my bad. Guess I just have the change operator to print even or odd . And thanks for the help
0
haha, yes I saw that. That's the answer I've been looking for and thanked you for haha. Thanks again :-). I am a beginner so these little things, which feels silly to me even gets me scratching my head. :(