Print out multiplication tables

Code:

def multiplicationTable(x,y):

    for row in xrange(x+1):

        for col in xrange(y+1):

            if row == 0 and col == 0:

                print 0,

                continue

            if row == 0:

                print col,

                continue

            if col == 0:

                print row,

                continue

            

            print row*col,

        print

   multiplicationTable(3,5)

Output:

0 1 2 3 4 5

1 1 2 3 4 5

2 2 4 6 8 10

3 3 6 9 12 15

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s