I have this problem—
Write code that will print a multiplication table for 10 positive integers across the columns and 10 positive integers down the rows. Prompt the user for the starting values for both the columns and the rows.
My attempt after some explanation from another question, which doesn’t print like Id expect it. Where do I call the print statements and what is wrong with the iterations
row = int(raw_input("Enter the first row number: " ))
col = int(raw_input("Enter the frist column number: "))
lastRow = row + 10
lastCol = col + 10
while (row < lastRow):
print "%4d" % (col * row)
while(col < lastCol):
print "%4d" % (col * row),
col += 1
print "%4d" % (col * row)
row += 1
Here’s a second go, better but not what I thought get
row = int(raw_input("Enter the first row number: " ))
col = int(raw_input("Enter the frist column number: "))
lastRow = row + 10
lastCol = col + 10
x=row
y=col
while (x < lastRow):
while(y < lastCol):
y += 1
print "%4d" % (y * x)
x += 1
Sorry about the duplicate post, I didn’t know that was bad etiquette
Quick edit that does the trick:
Problems in your code:
colkept atlastColvalue in the end of first cycle iteration. It should be reset to starting point after each rowprint‘srowincrement should be done inside of firstwhileAnd a tip: if you get stuck with problems like this, get a piece of paper, put down simple and small starting values: row = 1, col = 1, up to 3’s instead of 10’s. And reproduce your algorithm by hand, step by step.