322,409 views
21 votes
21 votes
THe code language is Python 3.

Write a program that contains a function that takes in a 2D list and an integer as parameters. The integer represents the limit of the values inside the list. The function should change any value in the list that is greater than that limit to be equal to limit, and any values less than -limit to be equal to -limit. For example, if the limit is 200, it should change 250 to 200, it should change -300 to -200, and leave any values between -200 and 200 unchanged. Finally, the function should print the resulting list. Ask the user for 25 integers, put them in a 5x5 list, ask the user for the limit, then call the function and output the result.

User Darkdante
by
2.6k points

1 Answer

11 votes
11 votes

Answer: N = 5ar = [0]*Nprint(ar)


Output[0, 0, 0, 0, 0]

Explanation: Python provides many ways to create 2-dimensional lists/arrays. However one must know the differences between these ways because they can create complications in code that can be very difficult to trace out. Let’s start by looking at common ways of creating a 1d array of size N initialized with 0s.

User Arkej
by
3.1k points