Write a program that creates a two dimensional array with 4 rows and 3 columns that contains the below numbers. Let the computer prompt you to enter these numbers.
After that, calculate and print the total and average of these values.
Answers
Explanation:
Python Exercise: Generates a two-dimensional array
Python Conditional: Exercise-11 with Solution
Write a Python program which takes two digits m (row) and n (column) as input and generates a two-dimensional array. The element value in the i-th row and j-th column of the array should be i*j.
Note :
i = 0,1.., m-1
j = 0,1, n-1.
Pictorial Presentation:
Python Exercise: Generates a two-dimensional array
Sample Solution:
Python Code :
row_num = int(input("Input number of rows: "))
col_num = int(input("Input number of columns: "))
multi_list = [[0 for col in range(col_num)] for row in range(row_num)]
for row in range(row_num):
for col in range(col_num):
multi_list[row][col]= row*col
print(multi_list)
Copy
Sample Output:
Input number of rows: 3
Input number of columns: 4
[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]]
Flowchart:
Flowchart: Python - Generates a two dimensional array
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program which iterates the integers from 1 to 50. For multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
Next: Write a Python program that accepts a sequence of lines (blank line to terminate) as input and prints the lines as output (all characters in lower case).
What is the difficulty level of this exercise?
EASY MEDIUM HARD
Based on 218 votes, average difficulty level of this exercise is Medium .
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Python: Data classes structure
>>> from dataclasses import dataclass
>>> @dataclass
>>> class DataClassCard:
>>> rank: str
>>> suit: str
>>> queen_of_hearts = DataClassCard('Q', 'Hearts')
>>> queen_of_hearts.rank
'Q'
>>> queen_of_hearts
DataClassCard(rank='Q', suit='Hearts')
>>> queen_of_hearts == DataClassCard('Q', 'Hearts')
True
New Content published on w3resource:
Scala Programming Exercises, Practice, Solution
Python Itertools exercises
Python Numpy exercises
Python GeoPy Package exercises
Python Pandas exercises
Python nltk exercises
Python BeautifulSoup exercises
Form Template
Composer - PHP Package Manager
PHPUnit - PHP Testing
Laravel - PHP Framework
Angular - JavaScript Framework
React - JavaScript Library
Vue - JavaScript Framework
Jest - JavaScript Testing Framework
by TaboolaSponsored LinksYou May Like
Win the Game with Ace of Spades at Your Hand! Join Now!
PariMatch
Born After 1960? Check Eligibility for 1Cr Term Insurance. Get Free Quote!
Term Plans -Compare & Buy Now!
खेलो रम्मी और जीत नकद रुपए। 2000 ज्वाइनिंग बोनस के साथ
RummyCircle
10 moisturising ingredients for shiny hair during winters
Skin & Hair Academy
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
©w3resource.com 2011-2020
PrivacyAboutContactFeedbackAdvertise
Sample Solution:
Python Code :
1. row_num = int(input("Input number of rows: "))
2. col_num = int(input("Input number of columns: "))
3. multi_list = [[0 for col in range(col_num)] for row in range(row_num)]
4.
5. for row in range(row_num):
6. for col in range(col_num):
7. multi_list[row][col]= row*col
8.
9. print(multi_list)