【发布时间】:2015-01-12 10:37:10
【问题描述】:
代码在用户输入后立即卡在 yes_or_no 函数中。没有错误信息,请帮助!正如你所看到的,我所做的只是进行一次简单的购买,我无法测试 buy_something 功能,我知道它可能有问题。
#!/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)
【问题讨论】:
-
“欢迎来到 Tittyland”,嗯?无论如何,您正在连续阅读两行输入。它不会卡住,它只是等待第二行。
-
作为一项规则——复制器应该只包含演示问题所需的最少代码。在这种情况下,这将是两行,而不是整个程序——也就是说,只有卡住的地方。有关更多指南,请参阅 stackoverflow.com/help/mcve。
标签: python