This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Eric Weinstein
about 11 years

The Big If

Hi everyone!

First, my apologies for the confusion surrounding the exercise The Big If. The below should help clear things up:

  1. Python doesn’t like mixed spaces and tabs when you indent a line. For that reason, it’s best to use four spaces (not the tab key!) when indenting. This forum answer should help you if you think indentation is the problem.
  2. The exercise is looking for a properly indented if/elif/else with at least one comparison (<=, >=, <, >, !=, or ==) and one boolean operator (and, or, or not). When indenting, make sure to indent the same amount on the line after each colon!
  3. Whatever your if/elif/else evaluates to should be True. Here’s an example of an if/elif/else that does all of the above, only I’ve left out the boolean operator requirement (since otherwise you could just cut/paste this answer!):

if 1 < 2:                # This is true...
    return True          # so True will be returned!
elif 1 > 2:
    return False
else:
    return False

For the boolean part, you can just use something like if True and True (which is True) or if not True (which is False) to meet all the requirements of the lesson.

I hope this helps, and apologies again for the confusion!

Answer 517ce6d8889f449b5a002a96

43 votes

Permalink

A lot of those answers here are helpful yet I might help someone but putting my solution as well.

 def theflyingcircus():
    if 9 <= 9:
        return True
        print "It's true"
    elif 6 == 8 or 99 < 88:
        return False
    else:
        return False

now as you know the positioning is crucial in python therefore be aware of that in every single move. if, elif and else is moved only by SPACEBAR (no Enter, no Tab). with the return and print I used Enter right after colon “:” double-check the spaces. it took me a lot of time to do this exercies, but for your own sake, do not copy&paste it.

points
Submitted by Jakub Zachnik
almost 11 years

17 comments

Sharan Reddy over 10 years

is it necessary that we need to use print over there?

godhatedices. over 10 years

no it is not

muugii_k23 over 10 years

it is work tnx

Derek C over 10 years

Another problem with good coding going bad umm well i have pretty much the exact same thing but it is throwing mine out for no bool operators when i do i am confused at why and i was wondering if someone might have an answer

FnRPJs about 10 years

I was getting so angry so i copy and pasted this and it still did not work. Turns out I needed to refresh my browser. So I used this and then went back and did my own to make sure I knew what I was doing….so if you get stuck and you swear your code is right then just refresh the page and try it again. (I’m using Firefox)

Chris Bennett about 10 years

Thank you so much!

Abu-Bakr about 10 years

you so save the day!

Mzuslin about 10 years

this is really helpful !thx!!!

the analist about 10 years

I COPY THIS AND GET SOOO MUCH GOOD NICE THINGS

gunther about 10 years

omg ive been struggling for ages thank you so much love you long time youve completed my life

yassinebouzbiba about 10 years

Thank you sir :0

gunther about 10 years

danny no one cares

Yrael about 10 years

i am having problems with indentation i didnt put in. eg it will tell me the indent on the elif statemnet is wrong even though it was there already.

surfer about 10 years

indent was my problem 2 ;solved!guys never forget to code in the right line

Anonymous about 10 years

dosent work

aputsey about 10 years

lol refreshing worked!

Steven Musante almost 10 years

Thank you I was totally lost

Answer 51458829ca49551635003ddd

28 votes

Permalink

i learned more from researching why this didn’t work than had it worked.

points
Submitted by monty.wolf
about 11 years

1 comments

Christopher over 10 years

Same Here. Poor examples and explination!

Answer 5102fe4cb952763335000b26

13 votes

Permalink

@Davide:

Rather than cutting/pasting, try typing the code out with exactly the same formatting as shown. Cutting/pasting may change the indentation of the lines, which will cause Python to raise an error.

points
Submitted by Eric Weinstein
about 11 years

20 comments

Kristofer Smith about 11 years

Its about time we get feedback from the people how wrote these lousy codes.

c0deninja about 11 years

Don’t stress. Count yourself lucky to be using this free service maintained mostly by kind people volunteering their time.

Kristofer Smith about 11 years

It says they are hiring, so they can go blow me for all I care.

Madura Balasubramanian about 11 years

Hey I tried that, still not working! Could you tell me how to fix it?

Shannon Gibson about 11 years

They may be hiring, but this is still a free service…

Chris Stanchak about 11 years

OMFG that was annoying. Thank God I found this post. Four spaces…not a tab. I think that should be somewhere in the tutorial…no?

kirsche17 about 11 years

Hey everybody! I just spent three hours trying everything to make this work! For me it worked like this: if 1 < 2 #four spaces in front of “if”!!! return True #six spaces in front of “return”!!! –> It was just about the right number of spaces in front of the “if” and “return”!

Hi Eric, why Python has such a problem between spaces and tab? Interesting…

thewelshgreen about 11 years

I could swear that in the tutorial it said tab, not four spaces. Now it’s the other way around? What? I dont-? WTH?

Skye Margot Mazur about 11 years

I think my spacing is fine here. I’ve got all the requirements. My error message just reads “Oops try again/true”

def the_flying_circus(): answer == “Yes” if answer == “Yes”: return True elif answer == “Yes” or “No”: return False else: return True

Cole Florence almost 11 years

+1

floris15 almost 11 years

this new editor doesn’t help. prefered the old one

anonymous almost 11 years

HEY GUYS ITS captainsparkelz

Cole Florence almost 11 years

No. Your not captainsparkelz

Seamus Cusack almost 11 years

Thanks Eric. The bit of info that got mine to work is “ When indenting, make sure to indent the same amount on the line after each colon! “

godhatedices. over 10 years

don’t mean to intrudes, but to be more specific, one of each should be selected ( == or !=, < or >, => or <=.) throughout if/elif/else statements in order to satisfy this exercise.

Zachary Jeans over 10 years

I think incorporating the ‘print’ function would be helpful req.

pbs257 over 10 years

This assignment doesn’t accept any valid solution for me. Quite frustrating. I am unable to continue…

yateendraji over 10 years

Eric: So glad you explained this. I was really scratching my head when my script worked in “real” python and not in the exercise. You explained why…

chych84 over 10 years

(: haha,I misunderstanding that the four spaces are in front of the “if” at first, so~ :( But now, it’s ok! I’m so happy! Thank you!

Answer 52b3d412548c35458d000dad

8 votes

Permalink

FWIW, my problem was with return keyword. I only saw it in the early examples and it was never explained the way that the print command was.

My first (failed) code here was:

def the_flying_circus():
    if 226 == 226:
        print "226 is teh ossum."
    elif True and False:
        print "is not true"
    else:
        print "and nope"

After eventually looking at the correct answers here and just trial and erroring, I finally added the return commands and made it work:

def the_flying_circus():
if 226 == 226:
    return True
    print "226 is teh ossum."
elif True and False:
    return False
    print "is not true"
else:
    return False
    print "and nope"
    
    

What’s odd about this lesson is that until now we’ve had Python do the work for us with regard to math and logic; suddenly here we’re ‘returning’ the answer to…I don’t know who the answer returns to.

Good luck repairing this exercise! Love the course anyway.

points
Submitted by Anthony Sims
over 10 years

5 comments

Schakra about 10 years

Same issue here. The “return” must be explained earlier.

rubyJumper18927 about 10 years

Ditto! I actually tried using return even though it bothered me it hadn’t been explained - was still getting an error but suppose it’s the indentation thing explains it. Thanks.

hoop4848 about 10 years

GOD BLESS YOU! I’ve tried everyone elses code and it wont work, but yours did!

Anonymouse almost 10 years

Yes!! Thank you!!

曉瑩劉 almost 10 years

Thank you very much!!!It is really helpful!!!

Answer 5141e4d743c0950823000272

5 votes

Permalink

a = “lets do it” def the_flying_circus():

 if a == "lets do it":
   return True
 elif True and False:
   return False
 else: 
   return False
points
Submitted by Nitish Murthy
about 11 years

11 comments

Ajinkya Rane almost 11 years

This works with copy and paste! Thanks!

Kelvin Yin almost 11 years

Thanks ! It really works :D

nobody can know almost 11 years

thanks is work

kachigar almost 11 years

wow! finally!

Myriam over 10 years

save me thanks you

Zaidhan over 10 years

it works thanks

grinfable over 10 years

omg thanks a ton!

CodeCS over 10 years

Thank you

SaN over 10 years

Thanks….

Milen Vasilchev over 10 years

Thank you!!!

Al almost 10 years

Omg! Thank You This was definately a good fix

Answer 518b9dd997623fc9b7001952

5 votes

Permalink

the real answer: def the_flying_circus(): # Start coding here! answer = “chloe”

if answer == "frog" or answer=="I am an idiot":

    return False

elif answer == "chloe" and 1==1:

    return True

else:

    return False
points
Submitted by GeOrGeHaRrIs
almost 11 years

8 comments

Abdul Lamont almost 11 years

thank you. you can have my bucket

Abdul jafingle almost 11 years

def the_flying_circus(): if 1==1 or 2==1+1: return True elif 5==3+2: return True else: return True

Mim Ahmetaj almost 11 years

def the_flying_circus(): answer = “Chloe” if answer == “Chloe” or answer==”I am an idiot”:

    return True

elif answer == "frog" and 1==1:

    return False

else:

    return True
TheCoder almost 11 years

I was wondering why this code was wrong. The console says that there is invalid syntax in line 3 and the “supportive” box is telling me to check my colons. I checked it and it still gives me the same response. Help.

monkey = “The monkey fell”

def the_flying_circus(): if monkey == “The monkey landed” or “The monkey stood up” not “The monkey made it into the pool”:

    return False


elif: monkey == "The monkey flew" and "The monkey flew across":


    return False
    

else: monkey == "The monkey fell":


    return True
NinthGG over 10 years

I tried all of the above code to answer this problem and this is the first solution that returned a correct answer

Yrael about 10 years

IndentationError: unindent does not match any outer indentation level wat does this mean????????

Octavian Liviu Dincan almost 10 years

tks

jack.sankalpgmail.com almost 10 years

thanks man..!!stucked there but your help ..

Answer 51bb83868c1cccc361002f98

5 votes

Permalink

Here we go, i can do it, in that way:

def the_flying_circus(): # Written By Renan Zapelini a = 100 b = 100 c = 200 if a == b: return True elif a != b and a > c: return False else: return False

points
Submitted by Renan Zapelini
almost 11 years

4 comments

Rohan N. Shetty about 10 years

i loved your code …

Renan Zapelini about 10 years

Thx. :)

Interesting! You the good fellow:)

Karthikeyan almost 10 years

awsome simple and cool!!!!!

Answer 5135b3cc75f2359a8b00250a

3 votes

Permalink

Here is the answer:

def the_flying_circus():
if 3>2:
    return True
elif 1>2 and 2>1:
    return False
else:
    return True
points
Submitted by faytuu
about 11 years

1 comments

kp_569 over 10 years

Thanks. Mine was too complicated.

Answer 51825dbeaf0d27fe5d00378b

3 votes

Permalink

the real answer!!! number = 2
def the_flying_circus():
if number < 3 and number > 1: return True elif number == 2: return True else: print “ Number is egal to 2” return True

points
Submitted by Adam
almost 11 years

1 comments

Jackdavis17 almost 11 years

no it doesnt!!!!!!!11

Answer 525324aff10c601a5100210b

3 votes

Permalink

Wow that was frustrating. How many people discontinue the course after that?

points
Submitted by jab2727
over 10 years

Answer 514a7ffec18ce47c1f000a7a

2 votes

Permalink

Eric,

If we wipe the code out and type it again, can we use tabs only? Is the reason it’s best to use 4 spaces idiosyncratic to this editor or just the lesson? This is an argument that [apparently][1] has no end, so low or high scope answers are equally good.

Thanks for the lessons! [1]: http://stackoverflow.com/questions/119562/tabs-versus-spaces-in-python-programming

points
Submitted by David Marquardt
about 11 years

Answer 51d308389c4e9d580e00f6f7

2 votes

Permalink

This work for me.

if 1 < 2 or 3 < 4: return True elif 1 > 2: return False else: return False

points
Submitted by Niv Binyamini
over 10 years

Answer 52c3ba8452f8633404003c50

2 votes

Permalink

Just wanted to share what I wrote this worked for me.

def the_flying_circus(): # Start coding here! if circus == fun or great: return True print “Amazing!” elif circus != fun: return False print “A waste of time.” else: return False

points
Submitted by shepardc484
about 10 years

Answer 512b98ff7d3198b27b006ac7

1 vote

Permalink

Hello Eric, Thanks a lot for the exercises. Very clever of you with the Big if solution. After some errors, I finally got it right. So kids, not just copy and paste!!!

points
Submitted by francisc@ montero e
about 11 years

1 comments

CJ almost 11 years

do you know who your talking to? -_-

Answer 5134a97a1c7126e886007df1

1 vote

Permalink

Thank you,I’ve solved this problem too. But then what should I do when I want to change another line to write new codes such as return or elif. By the way,I’m Chinese,it’s really difficult for me to figure out what this course is talking about.And I think it’s unnecessary to learn Python,maybe someone can translate it to Chinese.

points
Submitted by cn007
about 11 years

1 comments

Brian C. Jackson about 11 years

they have created a learning structure for this “general purpose” programming language. it will make more sense as you complete more and more units.

Answer 51452a1f1d0de980ce001e94

1 vote

Permalink

Hopefully this will help for some of you having a problem: My Code is below.

I was getting the same line error’s seen in this string, and I found out that it was a spacing error. Move your code 4 spaces on your 1st if line, as you will see in my code. Then move your return line 4 spaces on the second line. The code below is not keeping my spacing used in the exercise, so please use the 4 spaces for each and this should work for you!

I hope this helps you!!

def the_flying_circus(): # Start coding here! if 8 < 9: print “I get printed!” return True elif 8 > 9 or 7 > 8: print “I don’t get printed.” else: print “I also don’t get printed!”

points
Submitted by Falcon212
about 11 years

1 comments

Cole Florence almost 11 years

@Falcon212 Please use markdown to make your code be formatted as code. this will make it easier for others. Thanks.

Answer 514784fc4d18d32c03000f68

1 vote

Permalink

Thanks

points
Submitted by Max Rohoden
about 11 years

Answer 515af48e1d5bc6c33e00197e

1 vote

Permalink

okay sorry for that just use this code

def the_flying_circus(): if 1 < 666: print “Thanks PureAC” return True elif 893 > 932 or 32 > 32: print “asiaskdnasl.” else: print “asd”

# Start coding here!

and please tab it correctly if your still having problems feel free to ask me at [email protected]

points
Submitted by PureAC
almost 11 years

Answer 5190aad9641cf81604001950

1 vote

Permalink

this works

def the_flying_circus(): if 1==1 and 5==2*2+1: return True elif 5==5: return True else: return True

points
Submitted by tornadoelliott
almost 11 years

1 comments

tornadoelliott almost 11 years

you need to add spaces before certain lines

Answer 51d856f38c1ccc26dc02d9eb

1 vote

Permalink

else shall be always empty?

points
Submitted by aehp1113
over 10 years

Answer 51e388e18c1ccc06a7008288

1 vote

Permalink

This is my code. It worked perfectly.

def the_flying_circus():

if number < 3 and number > 1:
    return True
elif number == 2:
    return True
else:
    print " Number is equal to 2"
    return True
points
Submitted by Khidr
over 10 years

Answer 5220a3c380ff339a83002cd9

1 vote

Permalink

Thanks for this forum post. The instructions quite often are incredibly vague, you should really do something about it.

points
Submitted by 110608
over 10 years

Answer 526b9486548c3570f3000d31

1 vote

Permalink

def the_flying_circus(pythons):
if pythons > 0 < 100:
    return True
elif pythons > 100:
    return not True
else:
    return False

After some trouble with an unexplained syntax error on line 2, (I assumed it was an identation problem), I got this code to pass on the second attempt so use the spacebar instead of relying on enter/tab, since that’s what did the trick for me.

points
Submitted by Chris Alexander
over 10 years

Answer 52726cfc80ff334cf1000e2a

1 vote

Permalink

make it simple… def the_flying_circus(answer): if (2>1): return “True” elif True and False: return “False” else: return “True” print the_flying_circus(3)

points
Submitted by mike
over 10 years

Answer 527c877cabf821d9bd001d8a

1 vote

Permalink

def the_flying_circus(answer): if not 9 > 1 or 1 <= 5: return True elif 2 < 4: return 1 else: return 0

points
Submitted by 669167825
over 10 years

Answer 52c21270631fe9a1df004019

1 vote

Permalink

Thanks this helped so much!

points
Submitted by Neil Hemnani
about 10 years

Answer 52d70c2152f86307870021c1

1 vote

Permalink

def the_flying_circus(): # Start coding here! if 11> 10 or 10==10: return True elif 11 < 20: return False else: return True

        #no problem like this
points
Submitted by Tibu
about 10 years

Answer 52ff69fb282ae329a5003702

1 vote

Permalink

i copied this and tried some more but it keeps saying i have an indented block and it points at if File “python”, line 3 if 1 < 2: ^ IndentationError: expected an indented block

points
Submitted by Purpledom
about 10 years

Answer 535a837252f863e28800330d

1 vote

Permalink

Make sure that the_flying_circus() returns True

a = “lets do it” def theflyingcircus(): if a == “lets do it”: # Start coding here! return True # Don’t forget to indent # the code inside this block! elif True and False: return False # Keep going here. else: return False# You’ll want to add the else statement, too! – Don’t forget spaces

points
Submitted by m_AK47
almost 10 years

Answer 535e5802548c3590e4001866

1 vote

Permalink

can you guys help me

def the_flying_circus(): if answer > 5 : return elif answer < 5 : return else: return True

print greater_less_equal_5(4) print greater_less_equal_5(5) print greater_less_equal_5(6)

points
Submitted by Lauren Bunch
almost 10 years

Answer 520316aff10c60ce010002ad

0 votes

Permalink

Eric Weinstein you are one of the best teacher

points
Submitted by Nate
over 10 years

Answer 532e26917c82ca3eae0053a7

0 votes

Permalink

After spending at least one hour for this stupid code, I found the simplest way. It should be done as follows: def the_flying_circus(): if 5>3:
return True elif 5>10 or 3>5: return False else: return True Please, don’t copy&&paste that might cause an error. Cheers

points
Submitted by ElchinIsmayilov
about 10 years

Answer 535b989280ff33a5da000fe0

0 votes

Permalink

In case this helps someone else: I found that the thing I was missing was to add “return True” or “return False” after my Boolean statements, instead of just “print True”. This syntax was used but not explained in the other lessons, which is why I didn’t use it on my first attempts..!

def the_flying_circus():
if 3>2:
    return True
points
Submitted by DavidCallaghan
almost 10 years

Answer 513848c74790eeaf8100172b

-1 votes

Permalink

def theflyingcircus(): #Start coding here! response=5 if True and False: return False elif response==5: return True else: return False

This is my answer ,and I get to the next chapter !

points
Submitted by xrh123
about 11 years

Answer 510171cfcf22f779ec000326

-2 votes

Permalink

I’ve tried to copy and paste your code

if 1 < 2:                # This is true...
       return True          # so True will be returned!
elif 1 > 2:
       return False
else:
       return False

and I always get this error:

Traceback (most recent call last):
 File "runner.py", line 105, in compilecode
 File "python", line 4
elif 1 > 2:
   ^
SyntaxError: invalid syntax

How can I fix it? Thanks in advance. davide

points
Submitted by Davide Linosa
about 11 years

9 comments

Wiss Tsukaza about 11 years
  1. You need the function, 2. you need to us at least one comparaison & boolean
mkizzi11 about 11 years

mine is saying to check the indentation

Jonny Evans about 11 years

The whole point is you DONT COPY AND PASTE IDIOTS. READ THE WHOLE THING BEFORE YOU COMMENT STUPID THINGS. PROGRAMMERS ARE NOT STUPID. THEY WILL CLEAVE YOU FROM THE HERD.

Vlad about 11 years

def the_flying_circus(): if 3>2: return True elif 1>2 and 2>1: return False else: return True

Vlad about 11 years

put your cursor at the beginning of a line that starts ‘elif’ or ‘else’ (it should be indented). hit the

thewelshgreen about 11 years

I agree with you jonny, but try not to be so explosive. Geez.

Josh Johnson about 11 years

I’m not sure how to copy and paste an idiot…

David Marquardt about 11 years

You cull from a herd. You cleave a molecular bond, or a ham.

Cole Florence almost 11 years

@Davide Linosa Next time please post your questions in the Q&A section. this can be found in the editor at the footer of the page (with the new editor). or if you are using the old editor, it will be at the top.

Answer 51300f43d4ca2bb496002451

-2 votes

Permalink

Hi,

Here is the code I’m trying but I can’t seem to get it right:

def the_flying_circus(): jeff = “animator” if len(jeff) == 2 + 3: return True elif len(jeff) + 2 == 100**0.5 and 2 == 5 - 3: return True else: return False

Thanks in advance!

points
Submitted by Jeff Treves
about 11 years

6 comments

faytuu about 11 years

dude, it doesn’t work….

Jeff Treves about 11 years

Really?

Bruce Linington over 10 years

3+2 is 5.. there’s 4 letters in Jeff. Your elif reads as 4+2 = 6 == 50 and 2 ==2 5 == 50 and 2 == 2 and needs both to be true 6 == 50 #False So your code reads as: 4 == 5 #False 6 == 50 and 2 == 2 # False #False

Easy fix to this: if len(jeff) == 2+2

Sergey Zeygerman over 10 years

jeff is the variable name but the actual content of it is the string “animator” which contains 8 letters. It works out.

maysamfafa77 over 10 years

File “python”, line 3 jeff = “animator” ^ IndentationError: expected an indented block

maysamfafa77 over 10 years

whats wrong

Answer 515db370ee5665cdd000011a

-2 votes

Permalink

My answer:

def the_flying_circus():

a = 100
b = 200
c = 300

of a or b == c:
return True
elif a or b <= c:
return False
else:
return False

Nothing much, but thought I’d give my solution to the problem as well as others have =)

points
almost 11 years

3 comments

nobody can know almost 11 years

that doenst work !!!!!!!!!!!!!!!!!!!!

Cole Florence almost 11 years

It should work, try using proper indentation.

imbriacod about 10 years

It doesn’t work because of the “of” typo in the conditional.

Answer 517a93b1c03a5b66250037e2

-2 votes

Permalink

THE ANSWER IS FART NUGGET

points
Submitted by anonymous
almost 11 years

3 comments

Cole Florence almost 11 years

Spam is not appreciated here. This is for asking questions and learning.

anonymous almost 11 years

ITS NOT SPAM U NOOB

Cole Florence almost 11 years

Spam, as in using the stupid word “Noob” and improper spelling and capitalization is honestly not welcomed.

Answer 51382a9cc41abf894b000d6e

-3 votes

Permalink

I originally used comparisons but got nothing but errors. This is the code I used and it worked. Is this wrong?

answer = “‘Tis but a scratch!”

def black_knight_1(): if answer == “‘Tis but a scratch!”: return True else: “Tis not a scratch!”
return False

def black_knight_2(): if answer == “Go away, or I shall taunt you a second time!”: return True else: “Goes away”
return False

You’re input is greatly appreciated. Thanks in advance!!

points
Submitted by Lodog
about 11 years

1 comments

Cole Florence almost 11 years

@Lodog Next time please post your questions in the Q&A section. this can be found in the editor at the footer of the page (with the new editor). or if you are using the old editor, it will be at the top.

Answer 515337d02e7e783b4a001883

-4 votes

Permalink

Hi, What is the best way of “saying” this…? if 3>2: return True
elif 1>2 and 2>1: return False
else: return True

WHat is the intuition behind returning “True” on the else part? I get the If and Elif part but not the 3rd part.

Thx.

points
Submitted by cna892
about 11 years

2 comments

Cole Florence almost 11 years

@cna892 Next time please post your questions in the Q&A section. this can be found in the editor at the footer of the page (with the new editor). or if you are using the old editor, it will be at the top.

Moncef Bekhtaoui about 10 years

nothing is working for me