We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,610 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Python multiplication table and user input, need some help

Hello everyone, :)

I have exercise for class that I can't complete, I don't understand why my loops aren't
working

The question---
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---

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

Can anyone show me what I'm doing wrong

1
Contributor
1
Reply
51 Minutes
Discussion Span
1 Year Ago
Last Updated
3
Views
my.name
Newbie Poster
2 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Actually here' my new code that works except I need it to print and outer row and column that shows each value being multiples and I don't know where to place that code so if entered 1 and 1 it should look like this
http://www.mathsisfun.com/tables.html

row = int(raw_input("Enter the first row number: "   ))
col = int(raw_input("Enter the frist column number: "))

lastRow = row + 10
firstCol = col
lastCol = col + 10

 
while (row < lastRow):
    
    while(col < lastCol):
        
          
        print "%4d" % (col * row),
        col += 1
    
    col = firstCol
    row += 1
    print
my.name
Newbie Poster
2 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.2863 seconds using 2.65MB