unexplainable python

tec technic.tec at gmail.com
Sun Sep 27 05:33:16 CEST 2009


dads 写道:
> ...
> enter number: 34567
> _5digit function used
> 34 before sent to _2digit
> 34 slice when at _2digit function
> 34 before sent to plus_ten function
> 7 slice when at _2digit function
This is the point. _2digit() only gets 1 digit("7") and needs accessing 
the second byte in:
      var = self.plus_ten[n[0]+'0'] + ' ' + self._1digit(n[1])

> 7 before sent to plus_ten function
> 
> ...
> from __future__ import print_function
> import sys
> 
> class number(object):
> 
>     def _5digit(self, n):
> 
>         print(n[:2],'before sent to _2digit')
>         var = self._2digit(n[:2]) + ' thousand ' + self._4digit(n[2:])
You passed the last 3 digits to _4digit function.

>         return var
> 
> class control(object):
> 
>     def __init__(self):
>         pass
> 
>     def data_input(self):
> 
> 
>         while True:
>             i = raw_input('enter number: ')
>             if i == 's':
>                 break
>             #try:
>             n = number(i)
>             #except:
>             #    print('not a number')
> 
> 
> if __name__ in '__main__':
>     c = control()
>     c.data_input()



More information about the Python-list mailing list