[Tutor] first post
Steven D'Aprano
steve at pearwood.info
Sun Feb 1 15:53:03 CET 2015
Hi, and welcome!
My answers are below, interleaved between your comments.
On Sun, Feb 01, 2015 at 05:39:17PM +0530, sathya kumar Prasanna wrote:
> Hi guys,
>
> I am completely new to programming and have never had the opportunity to do
> attempt coding before. However I have started now and am facing my first
> problem.
> The code is as shown, I need to *fill in the blanks* such that when the
> code is run it gives the answer as "True".
I think the question you have been asked is underspecified. There are so
many possibly ways to answer this, and it isn't clear which ones are
acceptable. So I'm going to guess.
> #Please help.
>
> # Make sure that the_flying_circus() returns True
> def the_flying_circus():
> if ________: # Start coding here!
> # Don't forget to indent
> # the code inside this block!
> elif ________:
> # Keep going here.
> # You'll want to add the else statement, too!
I think they are hoping to demonstrate an if...elif...else block. But as
given, the question is silly, because the function takes no arguments
and always returns the same result! So, as a programmer, I would answer
that by writing:
def the_flying_circus(): # a terrible name for this function
return True
but unfortunately that doesn't answer the question of "fill in the
blanks", so we have to write a silly function that does needless work in
order to satisfy the question.
(I think you can tell I do not think much of this question. Is it from
Code Academy?)
So let's try again:
def the_flying_circus():
if 23 > 1000: # This is never true, so we can return anything.
return False
elif 1000 > 23: # This is always true, so return True.
return True
else:
# This is dead code (unreachable), it will never run.
return False
This should, I think, satisfy the question: it demonstrates an if
clause, an elif clause and an else clause. And it always returns True.
If you are wondering about the name of the function, the programming
language "Python" is not named after the snake, but after a British
comedy program of the 1970s called "Monty Python's Flying Circus", or
just Monty Python for short:
http://en.wikipedia.org/wiki/Monty_Python
Consequently, there is a common practice in Python programming circles
of using Monty Python related terms.
--
Steve
More information about the Tutor
mailing list