[Tutor] python coding problem

Alex Hall ahall at autodist.com
Mon Sep 26 14:06:25 EDT 2016


On Mon, Sep 26, 2016 at 11:35 AM, Richard Koeman <rkoeman at smcdsb.on.ca>
wrote:

> This is my first time using this so I hope it works.
> I am trying to find out why this code doesnt work.
> Its simple.  I want to find out which number is bigger.
>
> I hope you can help and that I am using this python feature properly.
> Thanks.
> The function prints the first two print statements then nothing else
> happens.
>
> def maximum(n1, n2):
>   print "the first number is" ,n1
>   print "the second number is", n2
>   if n1 > n2:
>     return
>

Using the 'return' keyword will return whatever follows it (nothing, in
this case). However, it also stops your function from doing anything else.
Think of it as telling the function "stop here, and do nothing else. Just
quit now."


>     print n1 , "is the bigger number"
>

This line will never execute, because you've already returned.


>   elif n1 < n2:
>     return n2
>
You now return a number, not nothing as before, but the result for your
function is the same. Your print statements must be *before* the return
statements.


>     print n2
>   elif n1 == n2:
>     print "they are equal"
>   else:
>     print "Sorry, No response found"
> maximum(1,2)
>
> --
> This is a staff email account managed by Simcoe Muskoka Catholic District
> School Board.  This email and any files transmitted with it are
> confidential and intended solely for the use of the individual or entity to
> whom they are addressed. If you have received this email in error please
> notify the sender.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Alex Hall
Automatic Distributors, IT department
ahall at autodist.com


More information about the Tutor mailing list