[Tutor] strange bidi requirement

Steven D'Aprano steve at pearwood.info
Wed Feb 24 23:57:20 CET 2010


On Thu, 25 Feb 2010 03:34:02 am rick wrote:
> I'm trying to write a math quiz program that replicates an old book
> on arithmetic.
>
> when it comes to summing a long column, I need to read the answer
> from the user, one digit at a time.
>
> so, if the answer should be something like
>
> 14238.83
>
> I would need to read the .03, then the .8, and so on.   I figure all
> strings, cast to int  (well, for this example, float).  Would this be
> easier if I learned some GUI programming?

Hell no! GUI programming is a whole new lot of stuff to learn! It's 
worth learning if you want a GUI interface, but not because it makes 
other things easier.


> Can it be done at all in just console?


Do you actually need to ask the user for one digit at a time? I don't 
imagine so, but could be wrong. So you can ask the user for the number 
at the console, and then process it in reverse:

>>> s = raw_input("Please enter a decimal number: ")
Please enter a decimal number: 123.456
>>>
>>> print s
123.456
>>>
>>> for c in reversed(s):
...     print c
...
6
5
4
.
3
2
1


Hope this helps.




-- 
Steven D'Aprano


More information about the Tutor mailing list