简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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