Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiplication Table
#1
So how can I create a multiplication table in python for a given number (user inputs a number, e.g "5" and table becomes "5x5"), column by column individually, rather than creating one whole table using a for loop like this:

for x in range (1, size + 1):
for y in range (1, size + 1):
print ('{:3}'.format(x*y), end="")
print()

I want to do it column by column individually instead. How can I do that?
Reply
#2
I don't understand what column by column means. Could you maybe show what you'd want the output to look like?
Reply
#3
Hi there, yes of course. so for example the output should be:

column one: 1 2 3 4 5
column two: 2 4 6 8 10
column three:3 6 9 12 15
column four: 4 8 12 16 20
column five: 5 10 15 20 25
Reply
#4
Hi there :)

I am trying to add numbers in a line, and was looking for help.

size = input("Enter number: ")
size = int(size)

step = 1
number = 1
ran = 1
while number < size:
    for x in range(ran, size + 1, step)
        print((str(ran)+"|"), x)
        number += 1
        ran += 1
        step += 1
This is my code atm and here is the output:
Output:
Enter number: 5 1| 1 2| 2 3| 3 4| 4 5| 5
What I want to do is to make 5 lines (or whatever number the user inputs) along each column, So that it will create a kind of multiplication table. Like so:

Output:
Enter number: 5 1| 1 2 3 4 5 2| 2 4 6 8 10 3| 3 6 9 12 15 4| 4 8 12 16 20 5| 5 10 15 20 25
Any ideas?
Reply
#5
Isn't that what your code already does? Maybe that's why I'm confused, lol

>>> for x in range(1, 6):
...   for y in range(1, 6):
...     print("{:3}".format(x*y), end="")
...   print()
...
  1  2  3  4  5
  2  4  6  8 10
  3  6  9 12 15
  4  8 12 16 20
  5 10 15 20 25
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  If statements and multiplication elroberto 1 1,684 Jun-22-2022, 05:35 PM
Last Post: deanhystad
  Find the maximum multiplication ercv 3 2,132 Nov-30-2020, 11:55 AM
Last Post: DeaD_EyE
  Multiplication Table Homework mcnhscc39 6 4,581 Nov-25-2018, 04:01 PM
Last Post: mcnhscc39
  creating a 3x3 multiplication table aditvaddi 1 3,609 Jun-18-2018, 06:05 AM
Last Post: volcano63
  Nested Loop multiplication table SushiRolz 3 10,204 Feb-28-2018, 04:34 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020