• Support PF! Buy your school textbooks, materials and every day products Here!

Printing a multipication table from user input

  • Thread starter mr.me
  • Start date
  • #1
49
0
My assignment was to "create a Python script that will allow the user to input the starting value for the row and column of a multiplication table and then print to screen the table containing ten columns and ten rows. Include a header for each row and column"

I was able to produce the calculated table and I was able to produce a header for each row, but not each column, I do not know where to put the print statement for such a thing, when I fiddle with it always prints incorrectly.

Any suggestions ?



The attempt at a solution__

Code:
row = int(raw_input("Enter the first row number: "   ))    
#These 2 lines prompt the user for input and store the value in "row" and "col"
col = int(raw_input("Enter the frist column number: "))

lastRow = row + 10               # These lines assign and store the value  of the variables
firstCol = col
lastCol = col + 10


while (row < lastRow):         #This line creates the conditions in which both loops operate             
    
    print row,"|",                   #Prints a header for each row 
    while(col < lastCol):         #This line creates the conditions for the inner loop
        
    
        print "%3d" %(col * row), #This line will calculate /print the values of the variables
        col +=1                           #This line  updates the value for which "col"
    
    col = firstCol
    
    row +=1                         #This line updates the value for "row"
    print
 

Answers and Replies

  • #2
33,310
5,004
The header for the columns should be printed before you print rows of the table. IOW, the print statement(s) should go above your while loop.
 

Related Threads on Printing a multipication table from user input

Replies
5
Views
5K
  • Last Post
Replies
4
Views
7K
Replies
2
Views
1K
Replies
6
Views
1K
Replies
0
Views
3K
Replies
2
Views
438
Replies
6
Views
4K
Replies
1
Views
852
Replies
1
Views
515
Top