[Tutor] Division problems

prasad rao prasadaraon50 at gmail.com
Tue Feb 3 09:42:20 CET 2009


HelloI wrote a function named vertical to print string .printable characters
and ASCII values in a table.
1)It is swallowing some characters.
2)It output some characters  2 or 3 times.
3)It prints one column more than what I asked for.

It may be a division problem(floating point).
Its sibling called horizontal got no problems.
please examine it  and give suggestions and improvements to set it right.

#!usr\\bin\\env python
def horizontal(columns):
import string
n=0
v=string.printable
v=v.replace('\n','')
v=v.replace('\t','')
while n<len(v):
  try:
for x in range (n,n+columns,1):
print '%s'%v[x],'=','%3d'%ord(v[x]),' '*3,
print
n+=columns
  except IndexError:break

def vertical(columns):
        import string
        v=string.printable
        v=v.replace('\n','')
v=v.replace('\t','')
        for x in range((len(v))/columns):
                for y in range(x,len(v),x+((len(v))/columns)):
                        print v[y],'=',ord(v[y]),' '*3,

                print


Thanks in advance.
Prasad.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090203/82aea26a/attachment.htm>


More information about the Tutor mailing list