[Tutor] multiplication table
prasad rao
prasadaraon50 at gmail.com
Sat Jan 10 12:01:49 CET 2009
HiI tried to print multiplication table using (*args) to pass parameters.and
tried
to print tables side by side.But the code looks messy .Is there a better way
to do it.
def mtab(*arg):
for x in range(1,11):
print '%3d'%(x),'x','%3d'%(arg[0]),'=','%3d'%(x*arg[0]),(' '*5),\
'%3d'%(x),'x','%3d'%(arg[1]),'=','%3d'%(x*arg[1]),(' '*5),\
'%3d'%(x),'x','%3d'%(arg[2]),'=','%3d'%(x*arg[2]),(' '*5)
print(('-')*10).center(78)
for x in range (1,11):
print '%3d'%(x),'x','%3d'%(arg[3]),'=','%3d'%(x*arg[3]),(' '*5),\
'%3d'%(x),'x','%3d'%(arg[4]),'=','%3d'%(x*arg[4]),(' '*5),\
'%3d'%(x),'x','%3d'%(arg[5]),'=','%3d'%(x*arg[5]),(' '*5)
Prasad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090110/12d669a4/attachment.htm>
More information about the Tutor
mailing list