169k views
2 votes
Write a program that creates a 4 x 5 list called numbers. The elements in your list should all be random numbers between -100 and 100, inclusive. Then, print the list as a grid.

For instance, the 2 x 2 list [[1,2],[3,4]] as a grid could be printed as:

1 2
3 4

Sample Output
-94 71 -18 -91 -78
-40 -89 42 -4 -99
-28 -79 52 -48 34
-30 -71 -23 88 59

Note: the numbers generated in your program will not match the sample output, as they will be randomly generated.

1 Answer

3 votes

Answer:

Solution

import random

numbers = [[random.randint(-100,100) for _ in range(5)] for _ in range(4)]

for row in numbers:

for num in row:

print(num, end=" ")

print()

User Pommicket
by
7.1k points