4 Replies - 1695 Views - Last Post: 09 December 2014 - 06:01 PM Rate Topic: -----

#1 cosmicbatz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-December 14

Need help with if statement error (python)

Posted 09 December 2014 - 04:54 PM

Hello everyone. I am sort of a noob to programming so you'll have to bare with me. I'm learning python from codecademy for now until I get a book on it. So I had to make an if statement with a comparator,and boolean and "the_flying_circus()" to return true. However, I keep on getting an error that says this: "Make sure your if/elif/else evaluates to True! (For instance, if your if branch condition is true, that branch should return True.)"

BTW the very top line that says: "def the_flying_circus" was already put in for me so I can't change it.

However as far as I can see it should end up true. It's probably a very dumb and large mistake. Here's my code:


def the_flying_circus():
    if not 9 + 10 == 21:   
        print "This better work"
        
    elif 2 + 2 == 4 or 2 + 4 <= 1:
        print "random words"
    else: 
        print "wat"


Could you help me figure out what's causing this? I couldn't find anything when I tried searching it up.

This post has been edited by jon.kiparsky: 09 December 2014 - 04:56 PM
Reason for edit:: [code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with if statement error (python)

#2 jon.kiparsky  Icon User is online

  • Beginner
  • member icon


Reputation: 10893
  • View blog
  • Posts: 18,588
  • Joined: 19-March 11

Re: Need help with if statement error (python)

Posted 09 December 2014 - 05:03 PM

What is it that you're expecting to have happen here, and what are you getting instead?

As I'm looking at it, the first statement should be True, which means you'll see "This better work" and nothing else. Is this what's happening? If not, what are you seeing instead?

View Postcosmicbatz, on 09 December 2014 - 06:54 PM, said:

I'm learning python from codecademy for now until I get a book on it.


I can suggest you search for Allen Downey's book "Think Python", from O'Reilly, which is available to read for free on line or as a free PDF. Also, I hear good things about Learn Python The Hard Way, which is also available on line for free.
Was This Post Helpful? 0
  • +
  • -

#3 cosmicbatz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-December 14

Re: Need help with if statement error (python)

Posted 09 December 2014 - 05:49 PM

[quote name='jon.kiparsky' date='09 December 2014 - 05:03 PM' timestamp='1418169808' post='2083170']
What is it that you're expecting to have happen here, and what are you getting instead?

As I'm looking at it, the first statement should be True, which means you'll see "This better work" and nothing else. Is this what's happening? If not, what are you seeing instead?

Here are the instructions I was given for it.

Write an if statement in the_flying_circus(). It must include:

if, elif, and else statements;
At least one of and, or, or not;
A comparator (==, !=, <, <=, >, or >=);
Finally, the_flying_circus() must return True when evaluated.
Don't forget to include a : after your if statements!
Was This Post Helpful? 0
  • +
  • -

#4 cosmicbatz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-December 14

Re: Need help with if statement error (python)

Posted 09 December 2014 - 05:59 PM

I fixed it. Thank you for your time. I'll definitely check out that book too.
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is online

  • Beginner
  • member icon


Reputation: 10893
  • View blog
  • Posts: 18,588
  • Joined: 19-March 11

Re: Need help with if statement error (python)

Posted 09 December 2014 - 06:01 PM

Ah, I see. So return a True - you can either do that at the end of the function, or from the single branch that will ever execute.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1