python-CSD-kursu/python-temel/get_random.py
2023-05-26 06:35:25 +03:00

25 lines
614 B
Python

import random
def get_random(a, b, size):
result = []
if isinstance(size, int):
for i in range(size):
result.append(random.randint(a, b - 1))
elif isinstance(size, tuple):
if len(size) != 2:
raise TypeError('tuple must have 2 elements!')
for i in range(size[0]):
col = []
for k in range(size[1]):
col.append(random.randint(a, b - 1))
result.append(col)
else:
raise TypeError('invalid type!')
return result
x = get_random(0, 10, 5)
print(x)
y = get_random(0, 10, (5, 4))
print(y)