簡體   English   中英

根據變量值相對於列表中其他值在列表中分配變量

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM