创建一个接受三个参数并打印一个整数的函数.
- 随机种子应设置为42.
- 第一个参数应该对应于np的大小.randint-0到10之间的值.
- 第二个参数是一个整数,你可以用它乘以randint.
- 第三个参数是一个值,您将为乘法结果编制索引
打印索引为"您的随机值为k"的整数
k=索引的结果
The program should not crash if the third value is larger than the first; it should not print anything to the screen.
Code
import sys
import numpy
import random
numpy.random.seed(42)
value1 = int(sys.argv[1])
value2 = int(sys.argv[2])
value3 = int(sys.argv[3])
def randomized(arg1, arg2, arg3):
x = numpy.random.randint(0, 10, size=arg1)
y = x * arg2
return y[arg3]
try:
random_value = randomized(value1, value2, value3)
print(f"Your random value is {random_value}")
except IndexError:
pass
randomized(value1, value2, value3)
Test Case Examples:
python3 reallyrandom.py 1 2 9
python3 reallyrandom.py 44 3 17
python3 reallyrandom.py 77 -3 55
python3 reallyrandom.py 2 4 10
Expected Output:
Your random value is 21
Your random value is -9
Error Message
Traceback (most recent call last):
File "reallyrandom.py", line 23, in <module>
randomized(value1, value2, value3)
File "reallyrandom.py", line 14, in randomized
return y[arg3]
IndexError: index 9 is out of bounds for axis 0 with size 1