Question

python Create an empty list of size 100 × 200 with all zeroes. How do you...

python

  1. Create an empty list of size 100 × 200 with all zeroes.

  2. How do you access the 4th row and 2nd column of a 2D list called

  3. Write a function called printList that takes as a parameter a 2D list and prints it to screen in row/column format.

  4. Create a multiplication table of size 10 × 10 that has all the products from 1 times 1 all the way up to 10 times 10.

  5. Create a 2D list (matrix) of size 100 × 100 with entries 0 except along the main diagonal which should be 1.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

rows, cols = (100, 200) #dimensions of list.

list = [[0]*cols]*rows #creating list with 0's.

print(list[4][2]) #accessing 4th row and 2nd column.

output:

2.

rows, cols = (5, 5) #dimensions of list.

list = [[0]*cols]*rows #creating list with 0's.

#printing the list in row column format.
for i in range(0,5):
for j in range(0,5):
print(list[i][j]," ",end='')
print()

output:

3.

#multiplication table from 1 times 1 to 10 times 10.
for i in range(1,11):
for j in range(1,11):
print(i, 'x', j, '=', i*j)

output:

Add a comment
Answer #2

To accomplish the tasks you've described in Python, follow the steps below:

  1. Create an empty list of size 100x200 with all zeroes:

pythonCopy codeempty_list = [[0 for _ in range(200)] for _ in range(100)]
  1. Access the 4th row and 2nd column of a 2D list:

Remember that Python uses zero-based indexing, so the 4th row and 2nd column would be accessed like this:

pythonCopy codevalue = your_2d_list[3][1]
  1. Write a function called printList to print a 2D list in row/column format:

pythonCopy codedef printList(lst):    for row in lst:        print(' '.join(str(elem) for elem in row))# Example usage:# printList(your_2d_list)
  1. Create a multiplication table of size 10x10:

pythonCopy codemultiplication_table = [[(i + 1) * (j + 1) for j in range(10)] for i in range(10)]
  1. Create a 2D list (matrix) of size 100x100 with entries 0 except along the main diagonal which should be 1:

pythonCopy codematrix = [[1 if i == j else 0 for j in range(100)] for i in range(100)]

These code snippets should help you accomplish the tasks you mentioned. Feel free to integrate them into your Python program or use them as needed.

answered by: Hydra Master
Add a comment
Answer #3

Here's a Python program that fulfills the requirements:

  1. Create an empty list of size 100 × 200 with all zeroes:

pythonCopy coderows = 100columns = 200two_d_list = [[0 for j in range(columns)] for i in range(rows)]
  1. Access the 4th row and 2nd column of a 2D list:

pythonCopy codeelement = two_d_list[3][1]  # Rows and columns are 0-indexed, so the 4th row is at index 3, and the 2nd column is at index 1.
  1. Write a function called printList to print a 2D list:

pythonCopy codedef printList(two_d_list):    for row in two_d_list:        print(" ".join(map(str, row)))  # Convert integers to strings and join them with spaces
  1. Create a multiplication table of size 10 × 10:

pythonCopy codesize = 10multiplication_table = [[i * j for j in range(1, size + 1)] for i in range(1, size + 1)]
  1. Create a 2D list (matrix) of size 100 × 100 with entries 0 except along the main diagonal which should be 1:

pythonCopy codesize = 100matrix = [[1 if i == j else 0 for j in range(size)] for i in range(size)]

You can use these snippets or combine them to create a complete Python program. For example:

pythonCopy codedef printList(two_d_list):    for row in two_d_list:        print(" ".join(map(str, row)))# Create an empty list of size 100 × 200 with all zeroesrows = 100columns = 200two_d_list = [[0 for j in range(columns)] for i in range(rows)]# Access the 4th row and 2nd column of the 2D listelement = two_d_list[3][1]# Print the 2D list using the printList functionprintList(two_d_list)# Create a multiplication table of size 10 × 10size = 10multiplication_table = [[i * j for j in range(1, size + 1)] for i in range(1, size + 1)]# Create a 2D list (matrix) of size 100 × 100 with entries 0 except along the main diagonal which should be 1size = 100matrix = [[1 if i == j else 0 for j in range(size)] for i in range(size)]

Feel free to use these code snippets and modify them according to your needs.


answered by: Mayre Yıldırım
Add a comment
Know the answer?
Add Answer to:
python Create an empty list of size 100 × 200 with all zeroes. How do you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as...

    Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as described below. Calls the function find_item_in_grid and prints the result. The find_item_in_grid function should have one parameter, which it should assume is a list of lists (a 2D list). The function should ask the user for a row number and a column number. It should return (not print) the item in the 2D list at the row and column specified by the user. The...

  • How to do this code? HW13.11. Create an HTML list from a Python list The function...

    How to do this code? HW13.11. Create an HTML list from a Python list The function below takes one parameter: a list, that contains only strings. Complete the function to create a unordered HTML list, as a string, and returns it. An empty list should return an empty HTML list with no list items. Do not add any extraneous whitespace to the HTML. For example, if given the list ["one", "two"], the function should return "<ul><li>one</li><li>two</li> </ul>". student.py IT TI...

  • This needs to be in python, however, I am having trouble with the code. Is there...

    This needs to be in python, however, I am having trouble with the code. Is there any way to use the code that I already have under the main method? If so, what would be the rest of the code to finish it? #Create main method def main(): #Create empty list list=[] #Display to screen print("Please enter a 3 x 4 array:") #Create loop for rows and have each entered number added to list for i in range(3): list.append([int(x) for...

  • Exercise 1 - Create a List to Sum Values Write a python script that sums the...

    Exercise 1 - Create a List to Sum Values Write a python script that sums the values in a list called add_list that contains the following values: (10, 2, -4, 8). Make sure you include a for loop when iterating through the list to sum the values. Take screenshots of the code and output. Exercise 2 – Create a Dictionary Write a python script that prints a dictionary where the key numbers are 1, 2, 3, 4, and 5 and...

  • Using RStudio, Create an R-Script: (1) You will generate a numeric matrix of size 21 by...

    Using RStudio, Create an R-Script: (1) You will generate a numeric matrix of size 21 by 21 and will name it tmp. To do so, draw 21×21 = 441 random observations from the standard normal distribution. Before doing so, set the seed for the random number generator to 37. See help for set.seed(). (2) Change the diagonal elements of tmp to 1s. (3) Calculate condition number of tmp. See help for cond(). (4) Calculate the inverse of tmp. See help...

  • Using RStudio, Create an R-Script: (1) You will generate a numeric matrix of size 21 by...

    Using RStudio, Create an R-Script: (1) You will generate a numeric matrix of size 21 by 21 and will name it tmp. To do so, draw 21×21 = 441 random observations from the standard normal distribution. Before doing so, set the seed for the random number generator to 37. See help for set.seed(). (2) Change the diagonal elements of tmp to 1s. (3) Calculate condition number of tmp. See help for cond(). (4) Calculate the inverse of tmp. See help...

  • In this assignment, you will create an application that holds a list of contact information. You ...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. MUST BE IN PYTHON FORMAT Create the folllowing objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • In this assignment, you will create an application that holds a list of contact information. You...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. Must Be In Python Format Create the following objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • In python, how do you create an array of unknown dimensional size? I want to create...

    In python, how do you create an array of unknown dimensional size? I want to create an array of unknown dimensional size based on a number I recieve. To elaborate, let's say n = 2, it will output a 3D array {true, true, true}. If n = 3, then its output will be a 4D array {true, true, true, true}. Whatever the n value is, the return value will be an array of n + 1 dimensional size. How would...

  • Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the...

    Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number Put a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT