[Tutor] Function not returning 05 as string

David Palao dpalao.python at gmail.com
Mon Apr 13 14:46:08 CEST 2015


Hello,
In the code that you posted, as it is, you are:
1) defining a function (numberentry)
2) defining a global variable (number01) and setting it to 0
3) calling numberentry discarding the result
4) printing the value of the global variable number01

I would guess that you want to store the result of the function and
print it. Is that correct?

Best

2015-04-13 14:11 GMT+02:00 Ken G. <beachkidken at gmail.com>:
> 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
> numberentry()
> print
> print number01
> END OF CODE:
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list