我是编码的初学者,我在这里有一个函数,它应该在调用时为字典添加一个键。它看起来像这样:
select a.*,'flag_1' as flag from table a
join
(select cast(min(startdate) as date) as minstartdate,cast(dateadd(day,30,min(startdate)) as date) as maxstartdate,ID from table
group by ID) adate
on cast(adate.maxstartdate as date)> cast(a.startdate as date)
and adate.id=a.id
where a.id=1
order by startdate
基本上,如果库存密钥大于或等于1,并且密钥不在项目字典中,我希望该功能减少库存并添加项目。如果库存大于1,我希望它添加一个键值。最后,如果库存小于1,我希望它打印“库存满”
这是dictionnary的项目:
def check_inventory(key):
if items["inventory"] >= 1 and items[key] not in items:
items[key] = 1
items["inventory"] -= items["inventory"]
elif items["inventory"] >= 1 and items[key] in items:
items[key] += 1
items["inventory"] -= items["inventory"]
elif items["inventory"] < 1:
return False
print "inventory full"
我这样称呼函数:
items = {"inventory": 1}
这是它给我的错误:
check_inventory("batteries")
无论如何希望你们都能帮助我。此外,如果你能解释错误代码,那就太好了!谢谢!