我怎样才能有一个程序会询问用户的最小和最大数量?

How can I have a program that will ask a minimum and maximum number from a user?

我怎样才能有一个程序来询问用户的最小值和最大值?,在给定的最小值和最大值之间生成一个包含 5 个随机数的列表,并显示另一个列表,其中的值是生成了 5 个数字?

这是我的代码。我只希望它显示每个数字及其对应的平方数。

from numpy import random
import numpy as np

#询问最小和最大数量

a=int(input("Minimum Number: "))
b=int(input("Maximum Number: "))

#随机元素和元素大小

x=random.randint(a,b , size=(5))

#5 个随机元素的列表

print("Generated Numbers:", x)

#5个随机元素的平方

print ("Squared Numbers:", np.square(x))

试试这个:

import random

value1 = int(input("Enter minimum value: "))
value2 = int(input("Enter maximum value: "))

randomValues = []
for i in range(5):
   randomvalue = random.randint(value1,value2)
   randomValues.append(randomvalue)

print("Got Random Values")
print(randomValues)
for value in randomValues:
   squareValue = value*value
   print("Sqare of value: "+str(value)+" is: "+str(squareValue))

Bro/Sis 我打这个答案有点快,如果你遇到任何语法错误或其他问题,请尝试解决它

编辑: *你可以跳过它转换​​成int,我以为它是float类型