Declare a 4 x 5 array called N.

Using for loops, build a 2D array that is 4 x 5. The array should have the following values in each row and column as shown in the output below:

1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5

Write a subprogram called printlt to print the values in N. This subprogram should take one parameter, an array, and print the values in the format shown in the output above.

Call the subprogram to print the current values in the array (pass the array N in the function call).

Use another set of for loops to replace the current values in array N so that they reflect the new output below. Call the subprogram again to print the current values in the array, again passing the array in the function call.

1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4

I really need help with this thanks. (In Python)

Respuesta :

Answer:

N = [1,1,1,1,1],

[2,2,2,2,2],

[3,3,3,3,3],

[4,4,4,4,4]

def printIt(ar):

  for row in range(len(ar)):

      for col in range(len(ar[0])):

          print(ar[row][col], end=" ")

      print("")

           

N=[]

for r in range(4):

  N.append([])

   

for r in range(len(N)):

  value=1

  for c in range(5):

      N[r].append(value)

      value=value + 1

           

printIt(N)

print("")

newValue=1

for r in range (len(N)):

  for c in range(len(N[0])):

      N[r][c] = newValue

  newValue = newValue + 1

       

printIt(N)

Explanation:

:D

Below is the required program of Python.

Python

Program:

# Array name will be "N".

# Start program

# Defining a function and taking input array

def printIt(ar):

# Using for loop to scan the rows as well as columns of array

 for row in range(len(ar)):

     for col in range(len(ar[0])):

# Printing the element of array

         print(ar[row][col], end=" ")

     print("")

# Passing the array N

N=[]

# Again using the loop

for r in range(4):

 N.append([])

# Loop to control rows

for r in range(len(N)):

 value=1

# Loop to control columns

 for c in range(5):

     N[r].append(value)

     value=value + 1

# Calling the function

printIt(N)

print("")

newValue=1

# Value in row and column

for r in range (len(N)):

 for c in range(len(N[0])):

# Assigning the values to the array

     N[r][c] = newValue

 newValue = newValue + 1

# Printing the array

# End program

printIt(N)

Program code:

  • Start a program.
  • Defining a function and taking input array
  • Using for loop to scan the rows as well as columns of array
  • Printing the element of array
  • Again using the loop to control rows and columns.
  • Assigning the values to the array
  • End program.

Output:

Find below the attachment of the output of the program code.

Find out more information about Python here:

https://brainly.com/question/26497128

Ver imagen Cricetus
ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE