2013-01-23 55 views
0

所以我有一个我正在做一个小型文字冒险店的功能。这里是代码:raw_input每次都会返回相同的内容吗?

def shop(): 
global p #prompt for raw_input 
global gold 
global arrows 

print""" 
You enter the small shop and the man at the counter asks "How can I help?" 
""" 

print""" 
"What would you like to buy?" He asks 
You look up at the list of items 
Copper Axe - 50G 
Copper Sword - 50G 
Wooden Bow - 30G 
Copper Arrows (20) - 20G 
Iron Axe - 100G 
Iron Sword - 100G 
Iron Arrows (20) - 40G 
Steel Axe - 200G 
Steel Sword - 200G 
Steel Arrows (20) - 80G 

or type 'exit' to exit the store 
    """ 
print"You have:" 
print inv 

op = raw_input(p) 

if op == "copper axe" or "Copper axe" or "Copper Axe" or "copper Axe": 
    if gold < 50: 
     print"You do not have enough gold" 
     shop() 
    else: 
     gold = gold - 50 
     inv.append("Copper Axe") 
     shop() 
if op == "copper sword" or "copper Sword" or "Copper sword" or "Copper Sword": 
    if gold < 50: 
     print"You do not have enough gold" 
     shop() 
    else: 
     gold = gold - 50 
     inv.append("Copper Sword") 
     shop() 
elif op == "Wooden bow" or "wooden bow" or "Wooden Bow" or "wooden Bow": 
    if gold < 30: 
     print"You do not have enough gold" 
     shop() 
    else: 
     gold = gold - 30 
     inv.append("Wooden Bow") 
     if arrows < 10: 
      print"You should probably buy some arrows" 
      shop() 
elif op == "Copper Arrows" or "copper arrows" or "Copper arrows" or "copper Arrows": 
    if gold < 20: 
     print"You do not have enough gold" 
     shop() 
    else: 
     gold = gold - 20 
     arrows = arrows + 20 
     inv.append("Copper Arrows: %p" % arrows) 
     shop() 
elif op == "iron axe" or "Iron axe" or "Iron Axe" or "iron Axe": 
    if gold < 100: 
     print"You do not have enough gold" 
     shop() 
    else: 
     gold = gold - 100 
     inv.append("Iron Axe") 
     shop() 
elif op == "iron sword" or "Iron Sword" or "Iron sword" or "iron Sword": 
    if gold < 100: 
     print"You do not have enough gold" 
     shop() 
    else: 
     gold = gold - 100 
     inv.append("Iron Sword") 
     shop() 
elif op == "iron arrows" or "Iron arrows" or "Iron Arrows" or "iron Arrows": 
    if gold < 40: 
     print"You do not have enough gold" 
     shop() 
    else: 
     gold = gold - 40 
     iarrows = iarrows + 20 
     inv.append("Iron arrows %a" % iarrows) 
     shop() 
elif op == "Steel Axe" or "steel axe" or "Steel axe" or "steel Axe": 
    if gold < 200: 
     print"You do not have enough gold" 
     shop() 
    else: 
     gold = gold - 200 
     inv.append("Steel Axe") 
     shop() 
elif op == "Steel Sword" or "steel sword" or "Steel sword" or "steel Sword": 
    if gold < 200: 
     print"You do not have enough gold" 
     shop() 
    else: 
     gold = gold - 200 
     inv.append("Steel Sword") 
     shop() 
elif op == "Steel Arrows" or "steel arrows" or "Steel arrows" or "steel Arrows": 
    if gold < 80: 
     print"You do not have enough gold" 
     shop() 
    else: 
     gold = gold - 80 
     sarrows = sarrows + 20 
     inv.append("Steel Arrows - %a" % sarrows) 
elif op == "exit" or "Exit": 
    menu() 
else: 
    synerr() #syntax error function 

基本上每次我运行它,不管原始输入是什么,它返回作为铜斧头。像这样:

You enter the small shop and the man at the counter asks "How can I help?" 


"What would you like to buy?" He asks 
You look up at the list of items 
Copper Axe - 50G 
Copper Sword - 50G 
Wooden Bow - 30G 
Copper Arrows (20) - 20G 
Iron Axe - 100G 
Iron Sword - 100G 
Iron Arrows (20) - 40G 
Steel Axe - 200G 
Steel Sword - 200G 
Steel Arrows (20) - 80G 

or type 'exit' to exit the store 

You have: 
[] 
>>>fkjas;ldkf 

You enter the small shop and the man at the counter asks "How can I help?" 


"What would you like to buy?" He asks 
You look up at the list of items 
Copper Axe - 50G 
Copper Sword - 50G 
Wooden Bow - 30G 
Copper Arrows (20) - 20G 
Iron Axe - 100G 
Iron Sword - 100G 
Iron Arrows (20) - 40G 
Steel Axe - 200G 
Steel Sword - 200G 
Steel Arrows (20) - 80G 

or type 'exit' to exit the store 

You have: 
['Copper Axe'] 
>>> 

那么有谁知道可能是什么原因造成的?

回答

0

这个表达式:

op == "copper axe" or "Copper axe" or "Copper Axe" or "copper Axe" 

评价是这样的:

(op == "copper axe") or "Copper axe" or "Copper Axe" or "copper Axe" 

这里有你想要的东西:

op == "copper axe" or op == "Copper axe" or op == "Copper Axe" or op == "copper Axe" 

顺便说一句,这里有一个快捷方式,转换为小写:

op.lower() == "copper axe" 
相关问题