Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

what is wrong with my code to test if a number is odd or even x=raw_input("enter a number:") print x if (x%2)==0: print "even" else: print "odd"

MIT 6.00 Intro Computer Science (OCW)
See more answers at
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer


To see the expert answer you'll need to create a free account at Brainly

i also tried replacing the print x line with int(x) to make sure the x being plugged in was an integer?
You would have to specify that the raw_input data is an int. Otherwise it looks as though it returns x as a string. Use: x = int(raw_input("Enter a number"))
ok that makes sense but if i used the function int(x) on the next line i don't see why it wouldn't return the same answer

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Ya it should work.
Oh no...x remains a string because it cannot be changed that way.
O Okay Thanks
Ex. x = 8 vs x = "8" x = 8 : x*2 = 16 x = "8" : x*2 = "88"
Okay Thanks
Onyx, when you said you replaced 'print x' with 'int(x)' is that all that was on that line? To make sure x is an int, you either need to wrap the raw_input in an int() or do x = int(x) afterwards. int(x) just returns x converted to an int, it doesn't alter x on its own.
Augh, I wish we could edit or delete posts.
haha - I said the same thing...or at least be able to edit them for the first 5 minutes or so!
Yeah that would be cool. Keen thanks i forgot about how functions don't actually change it, it only ouputs it. That would be very important haha. O and sorry about late response I have school so I'm not on much during the week.

Not the answer you are looking for?

Search for more explanations.

Ask your own question