Hi i am having difficulty in doing even and odd in lecture (1) looks weird i am getting a syntax error all the time. Please help.
>>> x = 15 >>> if (x/2)*2 ==x: print "even" SyntaxError: invalid syntax
Havent taken a look at it yet, but it looks like you are missing a bunch of variables. What is "even"? Is that all of your source code?
it didn't give me space to write the else code. It stopped at that level.
write your code on a text document and attach it :)
I am doing some trials but not as in lecture (1) don't know why.
It is invalid syntax because your "wording" did not make sense to python- This statement- [if (x/2)*2 ==x:] is fine, but [if (x/2)*2 =x:] is not because "=" assigns a value and does not "equate"
ok but why the result was 15 an even number ?
because 15/2 = 7.5 and 7.5*2 = 15
not the best way to test for even/odd number. On the other hand "%" works really well (which you did )
yes...Thanks a lot. Not used yet to " " and ( ) and this is giving me hard times but its fun. Thanks a lot again for helping me.
You are welcome :) I apologize for the improper use of tokens ( " ", [ ] ), but I am glad I was able to help.
Join our real-time social learning platform and learn together with your friends!