Plz comment on this code

Peter Otten __peter__ at web.de
Sun Sep 19 03:22:41 EDT 2010


fridge wrote:

> # bigdigits2.py
> 
> import sys
> 
> zero=["***",
>    "* *",
>    "***"]
> one=["***",
>   " * ",
>   "***"]
> digits=[zero,one,zero,one,zero,one,zero,one,zero,one]
>   
> inputted_digit=sys.argv[1]
> column_max=len(inputted_digit)
> row_max=3
> 
> r=0
> while r<3:
>  line=""
>  c=0
>  while c<column_max:
>   digit_i=int(inputted_digit[c])
>   digit=digits[digit_i]
>   line+=digit[r]
>   line+=" "
>   c+=1
>  print(line)
>  r+=1

- Add a docstring at the beginning of the script explaining what it is meant 
to do.
- Use four-space indent; add a space between names and operators.
- Replace the while-loops with for-loops. You can iterate over numbers and 
characters:

>>> for i in range(3):
...     print(i)
...
0
1
2
>>> for c in "abc":
...     print(c)
...
a
b
c

Peter



More information about the Python-list mailing list