PYTHON
Ask the user for a value N (0 ≤ N < 10)
Create a 2-D list in an N X N structure with integers 1-(N*N)
Print the list created
Reverse the list such that (1) each list in the 2D list is reversed and (2) the order of each list in the outer list is reversed (see example)
Print the reversed list
Example Execution
What size 2D list would you like to create?
N> 3
The original list is:
[ [1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
The reversed list is:
[ [9, 8, 7],
[6, 5, 4],
[3, 2, 1]
]
print("What size 2D list would you like to create?") n = int(input("N> ")) value = 1 lst = [] for i in range(n): temp = [] for j in range(n): temp.append(value) value += 1 lst.append(temp) print("\nThe original list is:") print(lst) reversedList = [] for i in range(len(lst)-1,-1,-1): reversedList.append(lst[i][::-1]) print("\nThe reversed list is:") print(reversedList)
Get Answers For Free
Most questions answered within 1 hours.