[Tutor] Codehelp: confused by the output in IDLE
Wolfram Kraus
kraus at hagen-partner.de
Fri Dec 16 12:45:21 CET 2005
vikas mohan wrote:
> Hi again!
>
> The following is a piece of code that I have written:
>
> def funcA(x): # function describiing the oddness or eveness of an x number
> if x%2 == 0:
> print x, "is even"
> else:
> print x, "is odd"
>
> def funcB(y): # function describiing the oddness or eveness of an y number
> if y%2 ==0:
> print y, "is even"
> else:
> print y, "is odd"
>
> # no more functions after this line
>
> *x=input("Please type a number: ")
> print x*
>
> *y=input("Please type another number: ")
> print y*
>
> *if x>y:
> print x,("is greater than"),y
> else:
> print y,("is greater than"),x*
>
> *if y and x >=0:
> print ("Both are positive numbers!")*
>
> print funcA(x)
> print funcB(y)
>
> And this is the output in IDLE after execution:
>
> *Please type a number: 5
> 5
> Please type another number: 10
> 10
> 10 is greater than 5
> Both are positive numbers!
> 5 is odd
> None
> 10 is even
> None*
>
>
> I don't understand why I am getting 2 instances of "None" in the output,
> when it has not been programmed by me. What is going on?
>
> Pls. advice
>
> Thanks again,
> V
You print inside your function (print x, "is odd") and you print the
result of your function (print funcA(x)). As your function doesn't
explicitly return a value, you get None, see:
http://www.python.org/doc/2.4.2/tut/node6.html#SECTION006600000000000000000
So either just call the function or return the string from your function.
HTH,
Wolfram
More information about the Tutor
mailing list