我正在尝试做一个Derp模拟器小游戏的东西'因为我很无聊,和一个问题突然出现,如果你试图购买猫粮它添加到库存猫粮,但不添加到猫粮计数,它不会带走钱。我使用一个单独的模块比实际的商店游戏文件,所以如果有人可以尝试,并找到什么是错的,我将不胜感激
我这样调用shop函数:
shop(inv, balance, catfood, liqpota)
车间代码:
from functions import *
def shop(inv, balance, catfood, liqpota):
while True:
print "Welcome to the shop."
print "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
print "( To purchase an item; enter the letter of the item. )"
print "( If you want to exit; enter 'back'. )"
print "A] $5 Cat Food - 'Not Just For Cats'"
print "B] $7 Liquified Potatoes - 'Who Would Want These?'"
print
com = raw_input("Purchase: ")
divider()
if com == "back" or com == "Back":
break
elif com == "a" or com == "A":
if "Cat Food" in inv:
if balance < 7:
print "You have insufficient funds."
elif balance > 7 or balance == 7:
catfood = catfood + 1
balance = balance - 7
print "Purcahse succcessful."
return catfood
return liqpota
if not "Cat Food" in inv:
if balance < 7:
print "You have insufficient funds."
elif balance > 7 or balance == 7:
catfood = catfood + 1
balance = balance - 7
inv.append("Cat Food")
print "Purchase successful."
return catfood
return liqpota
elif com == "b" or com == "B":
print "WIP"
break
else:
print "Invalid Item/Command."
divider()
主代码:(库存部分)
elif com == "inventory" or com == "Inventory":
tmp_invnum = 1
print "Cat Food = " + str(catfood)
print "Liquified Potatoes = " + str(liqpota)
print
for invf in inv:
print str(tmp_invnum) + "] " + invf
tmp_invnum += 1
第二个return语句(return liqpota)永远不会执行,因为函数在遇到第一个返回时结束。您可以在一条语句中返回所有值,并在函数调用时将它们解包。我在下面举了一个例子
相关问题 更多 >
编程相关推荐