Create a 4x7 table using an array and fill up the array with random values
Olivia Zamora
- Create a 4x7 table using an array and fill up the array with random values.
- Then find the column number (X) where the last row contains the smallest value.
Then find ratio_1, ratio_2, ratio_3 where
- ratio_1 = the value from last column of 1st row / the value from column X of 1st row
- ratio_2 = the value from last column of 2nd row / the value from column X of 2nd row
- ratio_3 = the value from last column of 3rd row / the value from column X of 3rd row
Notice that, X is the column number that you find in step 2.
22 Answers
from random import random
data = [ [int(random()*10) for j in range(7)] for i in range(4)
]Output
data = [ [2, 7, 8, 9, 8, 1, 1], [5, 7, 0, 9, 1, 8, 6], [6, 5, 8, 3, 7, 4, 8], [2, 5, 4, 0, 9, 8, 7]
] This should work:
from random import random
grid = [[], [], [], []]
for x in range(4): for y in range(7): grid[x].append(random())
last_numbers = [grid[0][6], grid[1][6], grid[2][6], grid[3][6]]
column_number = last_numbers.index(max(last_numbers))
ratio_1 = grid[3][0] / grid[column_number][0]
ratio_2 = grid[3][1] / grid[column_number][1]
ratio_3 = grid[3][2] / grid[column_number][2] 1