A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

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.

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

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

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

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

    1 Attachment
  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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"

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ok but why the result was 15 an even number ?

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  9. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  10. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  11. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  12. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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.