[英]assigning variables in a list based on its value in relation to the other values in the list
该函数以正整数n作为参数,并生成200至625之间的3个随机数,最小的随机数称为minValue,中间的随机数称为myTaret,最大的随机数称为maxValue。
def usingFunctionsGreater(n):
#create random numbers
aList=[]
for i in range(3):
aList.append(random.randrange(200,625,1))
#assign minValue, myTarget, and maxValue
注释应该有助于解释我要编写的程序,但是我不知道如何将变量分配给生成的列表中的元素。
怎么样:
>>> min, target, max = sorted([random.randrange(100, 625, 1) for i in range(3)])
>>> min, target, max
(155, 181, 239)
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.