[Tutor] Codehelp: confused by the output in IDLE
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"
> 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"
> 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
> 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
> Please type another number: 10
> 10 is greater than 5
> Both are positive numbers!
> 5 is odd
> 10 is even
> 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,
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:
So either just call the function or return the string from your function.
More information about the Tutor