Python - Week 4 - Multiplication Variants and Arrays
As I traveled to Canada, I read about arrays in Python. I also learned about how * operator is applied to repeat / concatenate.
Here is the problem statement:
Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i*j.
Suppose the following inputs are given to the program:
3,5
Then, the output of the program should be:
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
Here is the code, thanks to gist on github.
Some notes:Here is the problem statement:
Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i*j.
Suppose the following inputs are given to the program:
3,5
Then, the output of the program should be:
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
Here is the code, thanks to gist on github.
- In Python * means multiply for numbers, but repeat for strings—it’s like concatenating a string to itself repeatedly.
- The range built-in function generates a list of successive integers, starting from 0 be default and ending at upper bound - 1.
Comments
Post a Comment