# Multiplication Table in Python Homework Sample

Use a nested loop to display a multiplication table. The user should enter the size of the table to display (between 2 to 10). You can use print(value, end=””) so that the cursor does not move to a new line. During multiplications, the values may be different sizes, so you need to take that into account during the formatting. For more Python programming assignments contact us for a quote.

Solution:

print(“What size multiplication table would you like? (2 – 10):”)
a=int(input())
while a<2 or a>10:
print(“Invalid entry – Enter a number between 2 and 10”)
print(“What size multiplication table would you like? (2 – 10):”)
a=int(input())
f=””
print(” —Multiplication Table(“+str(a)+”*”+str(a)+”)—“)
for p in range(1,a+1):
if p==1:
print(” “+str(p),end=””)
else:
if p<10:
print(” “+str(p),end=””)
elif p<100:
print(” “+str(p),end=””)
else:
print(” “+str(p),end=””)
print(“”)
print(“———“,end=””)
for k in range(1,a+1):
print(“——“,end=””)
print(“”)
for i in range(1,a+1):
if i!=10:
print(str(i)+” |”,end=””)
else:
print(str(i)+” |”,end=””)
for j in range(1,a+1):
if (i%2==0 or (j-1)%2==0) and (j-1)!=0:
if j==a:
if i%2==0:
if i*j<10:
print(” # “+str(i*j)+” #\n”,end=””)
elif i*j<100:
print(” # “+str(i*j)+” #\n”,end=””)
else:
print(” # “+str(i*j)+” #\n”,end=””)
else:
if i*j<10:
print(” # “+str(i*j)+”\n”,end=””)
elif i*j<100:
print(” # “+str(i*j)+”\n”,end=””)
else:
print(” # “+str(i*j)+”\n”,end=””)
else:
if i*j<10:
print(” # “+str(i*j),end=””)
elif i*j<100:
print(” # “+str(i*j),end=””)
else:
print(” # “+str(i*j),end=””)
else:
if j==a:
if i*j<10:
print(” “+str(i*j)+” #\n”,end=””)
elif i*j<100:
print(” “+str(i*j)+” #\n”,end=””)
else:
print(” “+str(i*j)+” #\n”,end=””)
else:
if i*j<10:
print(” “+str(i*j),end=””)
elif i*j<100:
print(” “+str(i*j),end=””)
else:
print(” “+str(i*j),end=””)