在用戶輸入之後,代碼被卡在yes_or_no函數中。沒有錯誤信息,請幫忙!正如你可以看到我所要做的只是實現一個簡單的購買,我還沒有能夠測試buy_something函數,並且我意識到它可能有問題。在Python中製作RPG
#!/usr/bin/env python
import time
# Intro
print "Input Name:"
time.sleep(1)
name = raw_input()
print "Welcome to Tittyland brave %s'" %(name)
time.sleep(2)
print "You are given nothing but 500 gold to start you journey..."
time.sleep(2)
print "Good luck..."
time.sleep(3)
print "Shopkeeper: 'Eh there stranger! Looks like you'll need some gear before going into the wild! Check out my store!'"
time.sleep(4)
print ""
#Inventory and first shop
inventory = {
'pocket' : [],
'backpack' : [],
'gold' : 500,
}
shop = {
'dagger' : 50,
'leather armor' : 150,
'broadsword' : 200,
'health potion' : 75,
}
#Buying items
for key in shop:
print key
print "price: %s" % shop[key]
print ""
print "Shopkeeper: So, you interested in anything?"
answer1 = raw_input()
item = raw_input()
def buying_something(x):
for i in shop:
if shop[i] == x:
inventory[gold] -= shop[i]
inventory[backpack].append(shop[i])
def yes_or_no(x):
if x == 'yes':
print "Shopkeeper: 'Great! So what is your desire stranger"
buying_something(item)
else:
print "Shopkeeper: 'Another time then'"
yes_or_no(answer1)
「歡迎來到蒂特蘭」,呃?無論如何,你連續閱讀兩行輸入。它不會卡住,它只是等待第二行。 – JJJ 2014-11-14 22:50:30
作爲一項規則 - 複製者應該只包含證明問題所需的最小代碼。在這種情況下,這將是兩行,而不是整個程序 - 也就是說,*只是*卡住的地方。有關更多指導,請參閱http://stackoverflow.com/help/mcve。 – 2014-11-14 22:51:46