所以我试图设计两个函数,一个创建一个列表,一个检查列表中的某些参数。功能check()
功能是查看函数的随机生成列表中的任何元素是否> 100,然后通知用户需要记录哪些元素。说实话,我真的不知道从哪里开始check()
函数,并希望有人可能有一些建议?If/Else Statement and Lists Within Functions - Python 3.x
def price():
priceList = [1,2,3,4,5,6,7,8,9,10]
print ("Price of Item Sold:")
for i in range (10):
priceList[i] = random.uniform(1.0,1000.0)
print("${:7.2f}".format(priceList[i]))
print("\n")
return priceList
我知道check()
功能的路要走,但就像我说的,不完全知道从哪里去用它。
def check(priceList):
if priceList > 100
print ("This item needs to be recorded")
感谢您的高级帮助!
您是否需要检查'priceList'的所有元素是否都小于100?或者找到哪些元素比100大? –
'checkthese = [p for priceList如果p> 100]' – mpez0
价格表中没有任何初始值。您可以将price()的第一行更改为'priceList = []',因为无论如何,所有项目都将被随机值替换。 –