A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

ps9#2: quick question. for part #2 we have to write addShape to our shape set. My thinking is that I would test with an if statement to verify that the argument passed to the addShape is in fact a valid shape. What's odd is that the program works when I'm limited just to circles. however when I use an if statement with 'or' for circle,square,triangle, I get an error. can anyone explain what's going on? here's the circle example http://codepad.org/LK04Deey here's the circle, square, triangle example where I get a type error. http://codepad.org/T0bXeVGk

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

    maybe try the isinstance() function instead - http://docs.python.org/library/functions.html#type

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

    I figured it out. It was kinda obvious. I think if only takes one comparison/equality. You can't use 'or' within the if statement. http://codepad.org/kTzrKgPa

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

    http://dpaste.com/699312/

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

    you should be able to use multiple expresions (that evaluate to a boolean) seperated be or or and in an if statement - http://dpaste.com/699316/

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

    ah. I got my equalities screwed up. I need an 'and' statement instead of an 'or' statement. if it's the case that they are all 'not equal', then I don't have a valid shape. Thanks.

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

    or use or with == instead of != http://dpaste.com/699319/

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

    and using isinstance is easier if they are all subclasses of the same class http://dpaste.com/699332/

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

    thanks for all the feedback bwCA. really helps my understanding.

  9. 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.