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 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
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