Python: Create a multidimensional list with zeros
Python List: Exercise - 85 with Solution
Write a Python program to create a multidimensional list (lists of lists) with zeros.
Visual Presentation:
Sample Solution:
Python Code:
# Create an empty multidimensional list 'nums'
nums = []
# Loop over a range of 3 times to create 3 sublists
for i in range(3):
# Append an empty sublist to 'nums' for each iteration
nums.append([])
# Loop over a range of 2 times to fill each sublist with 2 zeros
for j in range(2):
# Append a zero to the current sublist for each iteration
nums[i].append(0)
# Print a message indicating the resulting multidimensional list
print("Multidimensional list:")
# Print the 'nums' list containing the structure of zeros
print(nums)
Sample Output:
Multidimensional list: [[0, 0], [0, 0], [0, 0]]
Flowchart:
Python Code Editor:
Previous: Write a Python program to round the numbers of a given list, print the minimum and maximum numbers and multiply the numbers by 5. Print the unique numbers in ascending order separated by space.
Next: Write a Python program to create a 3X3 grid with numbers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/list/python-data-type-list-exercise-85.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics