from lab10_classes import Pharmacy
def costliest_drug(pharmacy):
drug_list = []
cost_list = []
drug_list3 = []
most_expensive = 0
for name in pharmacy.inventory:
drug_list.append(name)
for key in pharmacy.unit_prices and pharmacy.inventory:
cost1 = pharmacy.unit_prices[key]
cost2 = pharmacy.inventory[key]
cost = cost1 * cost2
cost_list.append(cost)
for i in range(len(cost_list)):
if cost_list[i] > most_expensive:
most_expensive = cost_list[i]
drug_list3.append(drug_list[i])
continue
return drug_list3[len(drug_list3)-1]
我的返回值是正确的,它是单词“ Hydrochlorothiazide”;这就是我的返回值:
氢氯噻嗪
但是,我需要我的返回值看起来像这样:
['氢氯噻嗪']
它必须是列表中的字符串。我怎么做?
答案 0 :(得分:1)
您可以使用方括号在旅途中列出清单。因此,在您的情况下:
return [drug_list3[len(drug_list3)-1]]
应该可以解决问题。也可以使用str()
来创建字符串。