【发布时间】:2021-09-16 13:56:43
【问题描述】:
我有 2 个输入:
# The key is the available dates and the value is the price
a = {"g": 109192, "e": 116374, "o": 183368, "s": 162719}
# The dates that the user wants to take, this is going to be input by the user separeted by a space
b = ("g", "n", "e", "k", "s")
程序必须告诉用户日期的总费用以及可用的日期。
输出:
388285
g e s
到目前为止我的代码:
import json
a=input("")
b=list(input().split(' '))
dic=json.dumps(a)
def citas(dic,b):
citas_disponibles=[]
suma=0
for dia in b:
if dia in a:
suma += a[dia]
citas_disponibles.append(dia)
return citas_disponibles
citas(dic,b)
但“suma”会产生“错误”
【问题讨论】:
-
您的问题是什么?
b = g n e k s在 Python 中没有意义。 -
"b" 将由用户输入,我的意思是这样写,因为它将被空格分隔。
标签: python python-3.x python-2.7 dictionary dictionary-comprehension