Python Is This Python Multiplication Table Code Correct?

AI Thread Summary
A user seeks to create a Python function that generates a multiplication table for numbers 0 to 20 using nested lists. The initial implementation appends all products to a single list, resulting in a flat structure. Another participant confirms the function works but suggests modifying it to display results in separate rows for each multiplier. The discussion highlights that the placement of the list `Prod` should be inside the inner loop to ensure each row corresponds to the multiples of the respective number, thereby achieving the desired format.
mathmari
Gold Member
MHB
Messages
4,984
Reaction score
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
Hey mathmari!

It works for me. (Nod)
 
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:
 
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. 🤔
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top