Cash Register
Robert Brewer
fumanchu at amor.org
Tue May 11 15:47:14 EDT 2004
Ryan Q. wrote:
> It works, i'm just posting it hoping someone could do better.
>
> print ''
> print ' *** CASH REGISTER ***'
> print ' PRESS 0 AND THEN ENTER TO TOTAL'
> b = 1
> t = 0
> v = 0
> while b != 0:
> a = 1
> s = 0
> print ''
> while a != 0:
> a = input(' ITEM $ ')
> s = s + a
> print ' TOTAL $',s
> v = v + s
> cash = input(' CASH $ ')
> change = cash - s
> print ' CHANGE $',change
> print ' '
> print ' TOTAL SLAES $ ',v
Some thoughts:
1. You never modify 'b'. So instead of 'b = 1' and 'while b != 0:', just
say 'while True:'.
2. You really shouldn't use input()--it isn't safe. Use raw_input() and
some value-coercion instead.
3. More-descriptive variable names would help others understand your
code more easily and quickly; for example, use "subtotal" instead of
"s".
4. Is there any difference between "print ''" and "print"?
5. Where does 't' get used?
6. You can write "s += a" instead of "s = s + a", if you like. I do.
7. Minor nit (as if they aren't all minor nits): abusing whitespace to
line up arguments is frowned upon by Guido, according to PEP 8.
8. SLAES is misspelled. ;)
Hope that helps!
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list