Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Onyx Group Title

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"

  • 3 years ago
  • 3 years ago

  • This Question is Closed
  1. Onyx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i also tried replacing the print x line with int(x) to make sure the x being plugged in was an integer?

    • 3 years ago
  2. Aslander Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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"))

    • 3 years ago
  3. Onyx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • 3 years ago
  4. Aslander Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Ya it should work.

    • 3 years ago
  5. Aslander Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Oh no...x remains a string because it cannot be changed that way.

    • 3 years ago
  6. Onyx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    O Okay Thanks

    • 3 years ago
  7. Aslander Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Ex. x = 8 vs x = "8" x = 8 : x*2 = 16 x = "8" : x*2 = "88"

    • 3 years ago
  8. Onyx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Okay Thanks

    • 3 years ago
  9. Keen Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 3 years ago
  10. Keen Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Augh, I wish we could edit or delete posts.

    • 3 years ago
  11. Aslander Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    haha - I said the same thing...or at least be able to edit them for the first 5 minutes or so!

    • 3 years ago
  12. Onyx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 3 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.