menu = {
'1': dict(name='草莓冰淇淋', price=20),
'2': dict(name='香草冰淇淋', price=10),
'3': dict(name='香蕉冰淇淋', price=15),
'5': dict(name='巧克力冰淇淋', price=30),
}
def showmenu(menu):
for k, item in sorted(menu.items()):
print "%(key)s: %(name)s 价格%(price).2f" % dict(key=k, **item)
def menuchoice(menu):
while True:
showmenu(menu)
c = raw_input("Your Choice('.' for end): ")
if c == '.':
break
else:
yield menu.get(c)
customerchoice = filter(None, menuchoice(menu))
print "Total: %.2f" % sum(map(lambda x: x["price"], customerchoice))
# coding=utf-8input_string = '食材1,食材2,食材3' # 你输入的格式
input_list = input_string.split(',')
result = [] # 保存所有组合到列表result
for i in input_list:
for j in input_list:
if i != j:
result.append(i + j)
# 挨个打印出result列表的元素, 即为你想要的结果
for i in result:
print i
如果你想用 Python 代码表示 "体重减 150 × 0.6 + 48" 的计算式,可以这样写:weight = 150
result = weight - (150 * 0.6) + 48
print(result)
这段代码中,我们首先定义了一个变量 weight,并将其赋值为 150。然后我们使用 Python 的运算符对 weight 进行计算,最后使用 print 函数将结果输出到控制台。
运行这段代码后,你会看到输出结果为 "48"。