This forum is now read-only. Please use our new forums! Go to forums
The Big If
Hi everyone!
First, my apologies for the confusion surrounding the exercise The Big If. The below should help clear things up:
- 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.
- The exercise is looking for a properly indented if/elif/else with at least one comparison (
<=
,>=
,<
,>
,!=
, or==
) and one boolean operator (and
,or
, ornot
). When indenting, make sure to indent the same amount on the line after each colon! - 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
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.
Answer 51458829ca49551635003ddd
i learned more from researching why this didn’t work than had it worked.
1 comments
Same Here. Poor examples and explination!
Answer 5102fe4cb952763335000b26
@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.
20 comments
Its about time we get feedback from the people how wrote these lousy codes.
Don’t stress. Count yourself lucky to be using this free service maintained mostly by kind people volunteering their time.
It says they are hiring, so they can go blow me for all I care.
Hey I tried that, still not working! Could you tell me how to fix it?
They may be hiring, but this is still a free service…
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?
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…
I could swear that in the tutorial it said tab, not four spaces. Now it’s the other way around? What? I dont-? WTH?
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
+1
this new editor doesn’t help. prefered the old one
HEY GUYS ITS captainsparkelz
No. Your not captainsparkelz
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! “
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.
I think incorporating the ‘print’ function would be helpful req.
This assignment doesn’t accept any valid solution for me. Quite frustrating. I am unable to continue…
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…
(: 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
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.
5 comments
Same issue here. The “return” must be explained earlier.
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.
GOD BLESS YOU! I’ve tried everyone elses code and it wont work, but yours did!
Yes!! Thank you!!
Thank you very much!!!It is really helpful!!!
Answer 5141e4d743c0950823000272
a = “lets do it” def the_flying_circus():
if a == "lets do it":
return True
elif True and False:
return False
else:
return False
11 comments
This works with copy and paste! Thanks!
Thanks ! It really works :D
thanks is work
wow! finally!
save me thanks you
it works thanks
omg thanks a ton!
Thank you
Thanks….
Thank you!!!
Omg! Thank You This was definately a good fix
Answer 518b9dd997623fc9b7001952
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
8 comments
thank you. you can have my bucket
def the_flying_circus(): if 1==1 or 2==1+1: return True elif 5==3+2: return True else: return True
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
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
I tried all of the above code to answer this problem and this is the first solution that returned a correct answer
IndentationError: unindent does not match any outer indentation level wat does this mean????????
tks
thanks man..!!stucked there but your help ..
Answer 51bb83868c1cccc361002f98
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
4 comments
i loved your code …
Thx. :)
Interesting! You the good fellow:)
awsome simple and cool!!!!!
Answer 5135b3cc75f2359a8b00250a
Here is the answer:
def the_flying_circus():
if 3>2:
return True
elif 1>2 and 2>1:
return False
else:
return True
1 comments
Thanks. Mine was too complicated.
Answer 51825dbeaf0d27fe5d00378b
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
1 comments
no it doesnt!!!!!!!11
Answer 525324aff10c601a5100210b
Answer 514a7ffec18ce47c1f000a7a
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
Answer 51d308389c4e9d580e00f6f7
This work for me.
if 1 < 2 or 3 < 4: return True elif 1 > 2: return False else: return False
Answer 52c3ba8452f8633404003c50
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
Answer 512b98ff7d3198b27b006ac7
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!!!
1 comments
do you know who your talking to? -_-
Answer 5134a97a1c7126e886007df1
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.
1 comments
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
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!”
1 comments
@Falcon212 Please use markdown to make your code be formatted as code. this will make it easier for others. Thanks.
Answer 514784fc4d18d32c03000f68
Answer 515af48e1d5bc6c33e00197e
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]
Answer 5190aad9641cf81604001950
this works
def the_flying_circus(): if 1==1 and 5==2*2+1: return True elif 5==5: return True else: return True
1 comments
you need to add spaces before certain lines
Answer 51d856f38c1ccc26dc02d9eb
Answer 51e388e18c1ccc06a7008288
Answer 5220a3c380ff339a83002cd9
Answer 526b9486548c3570f3000d31
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.
Answer 52726cfc80ff334cf1000e2a
Answer 527c877cabf821d9bd001d8a
Answer 52c21270631fe9a1df004019
Answer 52d70c2152f86307870021c1
Answer 52ff69fb282ae329a5003702
Answer 535a837252f863e28800330d
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
Answer 535e5802548c3590e4001866
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)
Answer 520316aff10c60ce010002ad
Answer 532e26917c82ca3eae0053a7
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
Answer 535b989280ff33a5da000fe0
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
Answer 513848c74790eeaf8100172b
Answer 510171cfcf22f779ec000326
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
9 comments
- You need the function, 2. you need to us at least one comparaison & boolean
mine is saying to check the indentation
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.
def the_flying_circus(): if 3>2: return True elif 1>2 and 2>1: return False else: return True
put your cursor at the beginning of a line that starts ‘elif’ or ‘else’ (it should be indented). hit the
I agree with you jonny, but try not to be so explosive. Geez.
I’m not sure how to copy and paste an idiot…
You cull from a herd. You cleave a molecular bond, or a ham.
@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
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!
6 comments
dude, it doesn’t work….
Really?
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
jeff is the variable name but the actual content of it is the string “animator” which contains 8 letters. It works out.
File “python”, line 3 jeff = “animator” ^ IndentationError: expected an indented block
whats wrong
Answer 515db370ee5665cdd000011a
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 =)
3 comments
that doenst work !!!!!!!!!!!!!!!!!!!!
It should work, try using proper indentation.
It doesn’t work because of the “of” typo in the conditional.
Answer 517a93b1c03a5b66250037e2
3 comments
Spam is not appreciated here. This is for asking questions and learning.
ITS NOT SPAM U NOOB
Spam, as in using the stupid word “Noob” and improper spelling and capitalization is honestly not welcomed.
Answer 51382a9cc41abf894b000d6e
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!!
1 comments
@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
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.
2 comments
@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.
nothing is working for me
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
17 comments
is it necessary that we need to use print over there?
no it is not
it is work tnx
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
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)
Thank you so much!
you so save the day!
this is really helpful !thx!!!
I COPY THIS AND GET SOOO MUCH GOOD NICE THINGS
omg ive been struggling for ages thank you so much love you long time youve completed my life
Thank you sir :0
danny no one cares
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.
indent was my problem 2 ;solved!guys never forget to code in the right line
dosent work
lol refreshing worked!
Thank you I was totally lost