简体   繁体   English

根据变量值相对于列表中其他值在列表中分配变量

[英]assigning variables in a list based on its value in relation to the other values in the list

This function takes, as an argument, a positive integer n and generates 3 random numbers between 200 and 625, the smallest random number will be called minValue, the middle random number will be called myTaret, and the largest random number will be called maxValue. 该函数以正整数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

the comments should help explain the program that i want to write, but I have no clue how to assign the variables to the elements in the list that is generated. 注释应该有助于解释我要编写的程序,但是我不知道如何将变量分配给生成的列表中的元素。

How about the following: 怎么样:

>>> 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM