Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 19 Online
OpenStudy (anonymous):

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.

OpenStudy (anonymous):

>>> x = 15 >>> if (x/2)*2 ==x: print "even" SyntaxError: invalid syntax

OpenStudy (anonymous):

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?

OpenStudy (anonymous):

it didn't give me space to write the else code. It stopped at that level.

OpenStudy (anonymous):

write your code on a text document and attach it :)

OpenStudy (anonymous):

I am doing some trials but not as in lecture (1) don't know why.

OpenStudy (anonymous):

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"

OpenStudy (anonymous):

ok but why the result was 15 an even number ?

OpenStudy (anonymous):

because 15/2 = 7.5 and 7.5*2 = 15

OpenStudy (anonymous):

not the best way to test for even/odd number. On the other hand "%" works really well (which you did )

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

You are welcome :) I apologize for the improper use of tokens ( " ", [ ] ), but I am glad I was able to help.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!