Python multiplication table with while loops only -


my task create multiplication table looking this user asked put in 2 numbers between 1 , 9. (in picture user put in "rows=3" "col=5").

i can't top row right, way make code better? "better" mean make whole thing 2 while loops?

edit: forgot mention while loops, not "for".

row=int(input("number of rows:")) col=int(input("number of cols:")) x=1 m=1 amount=col while amount>0:     print("%5d"%m, end="")     m=m+1     amount-=1 print() while x<(row+1):     y=1     print(x, end="")     while y<(col+1):         print("%4d"%(x*y), end="")         y=y+1     print("\n")     x=x+1 

juste manage table in heart of loops. can have 1 loop while i*j <=row*col if better minimum of loops. loop best solution problem.

row,col=3,5 i=0 while <= row :     j=0     while j <= col:         if i+j==0 : print('{:4s}'.format(''),end='') #corner         elif i*j==0 : print('{:4d}'.format(i+j),end='') # border         else : print('{:4d}'.format(i*j),end='') # table         j=j+1        print()     i=i+1 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -