[Tutor] Function not returning 05 as string

Dave Angel davea at davea.name
Mon Apr 13 14:18:55 CEST 2015


On 04/13/2015 08:11 AM, Ken G. wrote:
> I am sure there is an simple explanation but when I input
> 5 (as integer), resulting in 05 (as string), I get zero as the end
> result. When running the code:
>
> START OF PROGRAM:
> Enter the 1st number:  5
>
> 05
>
> 0
> END OF PROGRAM:
>
> START OF CODE:
> import sys
>
> def numberentry():
>      print
>      number01 = raw_input("Enter the 1st number:  ")
>      if number01 == "0":
>          sys.exit()
>      if  len(number01) == 1:
>          number01 = "0" + number01
>      print
>      print number01
>      return(number01)
>
> number01 = 0

What is this line intended to do?

> numberentry()

Where are you intending to store the return value?  Currently, you're 
just throwing it away.

> print
> print number01

This variable has no relation to the one in the function.  In fact, I'd 
recommend you use a different name, to make that clear.

> END OF CODE:


-- 
DaveA


More information about the Tutor mailing list