我的代码要求提供产品列表或从文件中加载它们。然后,我需要找出哪个值是最小的,如果有同样小的元素,选择一个随机的。但是,我仍然需要将该值链接到其相关字符串。到目前为止,我有:
def checkPrices(products):
for x in range(len(products)):
if (x)%3 == 0:
name = str(products[x])
print(name)
elif (x+1)%3 == 0:
quantity = int(products[x])
print(quantity)
pricePerUnit = str(format(price/quantity, '.2f'))
print(name + " is $" + pricePerUnit + " per unit")
elif (x)%1 == 0:
price = float(products[x])
print(price)
我怎样才能扩展它,以便我可以找到每单位的最低价格,然后打印如下内容:
I would recommend product1