Multiplication Table Generator

In summary, the conversation discusses writing a function in Python that returns a multiplication table of $20\times 20$ using lists. The code provided by the speaker uses two nested for-loops to generate the table and a mistake is pointed out in the placement of the empty list. The speaker also suggests a change to the code to display the results in separate rows, which is agreed upon.
  • #1
mathmari
Gold Member
MHB
5,049
7
Hey! 😊

I want to write a function in Python that returns the multiplication table $20\times 20$.

We do that using lists in lists, right? I have written the following :

Code:
def mul_table() : 
    Prod = []  
    Table = [] 
    for i in range(21) : 
        for j in range(21) : 
            Prod.append(i*j) 
        Table.append(Prod)
    return Table 
    
print(mul_table())
Is that correct? :unsure:
 
Technology news on Phys.org
  • #2
Hey mathmari!

It works for me. (Nod)
 
  • #3
Klaas van Aarsen said:
It works for me. (Nod)

Could we make a change so that the result gives in different rows? I means all multiplers of 0 in the first row, in the second row all multiples of 1,etc? :unsure:
 
  • #4
mathmari said:
Could we make a change so that the result gives in different rows? I means all multiplers of 0 in the first row, in the second row all multiples of 1,etc?
Ah, I see now that Prod = [] is in the wrong spot.
It should be inside the for-loop. (Worried)

Then the first row will contain only all multiples of 0. 🤔
 

1. What is a multiplication table?

A multiplication table is a grid that shows the products of two numbers. It is a useful tool for learning and memorizing multiplication facts.

2. How do I read a multiplication table?

To read a multiplication table, find the number at the top of the column and the number at the left of the row. The product of these two numbers will be located at the intersection of the row and column.

3. Why is it important to know the multiplication table?

Knowing the multiplication table is important because it is the foundation for many mathematical concepts and practical skills, such as division, fractions, and solving equations. It also helps with mental math and can save time when solving problems.

4. How can I memorize the multiplication table?

One way to memorize the multiplication table is through practice and repetition. You can also use mnemonic devices, such as songs or rhymes, to help you remember the facts. Another helpful tip is to focus on one number at a time and practice its multiplication facts until you have them memorized.

5. Are there any patterns in the multiplication table?

Yes, there are several patterns in the multiplication table that can make it easier to remember the facts. For example, the products of any number multiplied by 0 will always be 0, and the products of any number multiplied by 1 will always be that number. There are also patterns within each row and column, such as the multiples of 10 always ending in 0 and the multiples of 5 always ending in 5.

Similar threads

  • Programming and Computer Science
Replies
4
Views
3K
Replies
3
Views
757
  • Programming and Computer Science
2
Replies
55
Views
4K
  • Programming and Computer Science
Replies
7
Views
399
  • Programming and Computer Science
Replies
34
Views
2K
  • Programming and Computer Science
Replies
8
Views
786
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
4
Views
980
  • Programming and Computer Science
Replies
4
Views
861
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top