我需要一些函数的帮助,第一次调用它时,它运行得很好,但是在后续运行if / else语句时它会给出TypeError'int'不可调用。为了看到这个,当给出选项使用Hunt时,然后在第二次运行时再次使用Hunt。我使用的是Python 2.7,代码是: -
from sys import exit
import random
equipment = ['Bolter', 'Bolt Pistol', 'Combat Knife']
print "Your ship has crash landed on an unknown planetoid, what do you do?
Explore, Overwatch, Hunt or Nothing"
def enemy_attack():
enemy_attack = random.randrange(0, 7)
if enemy_attack <= 5:
print "Enemy Misses"
print "Your Turn"
you_attack()
elif enemy_attack == 6:
print "Enemy kills you"
else:
print "Enemy ran away"
def you_attack():
you_attack = random.randrange(0, 7)
if you_attack <= 2:
print "You missed"
print "Thier Turn"
enemy_attack()
else:
print "You killed the enemy"
print "What do you do? Explore, Overwatch, Hunt, or Nothing"
do = raw_input("> ")
if "Explore" in do:
print "You find a sealed container"
print "Your Equipment is", equipment
print "Do you want to open the container? Yes or No"
container = raw_input("> ")
if "Yes" in container:
open_container()
else:
print "You left it alone"
elif "Overwatch" in do:
print "Orks Attack!!!"
enemy_attack()
elif "Hunt" in do:
print "You attack the Orks!"
you_attack()
else:
print "The planetoid swallows you whole, and adds your mass to it!!"
exit(0)
def open_container():
open_container = random.randrange(0,5)
if open_container == 0:
print "You have found a Plasma Gun!"
equipment.append('Plasma Gun')
print "Your equipment is now", equipment
elif open_container == 1:
print "You have found a Chainsword!"
equipment.append('Chainsword')
print "Your equipment is now", equipment
elif open_container == 2:
print "You have found a Power Sword"
equipment.append('Power Sword')
print "Your equipment is now", equipment
else:
print "There is nothing here for you!!"
do = raw_input("> ")
if "Explore" in do:
print "You find a sealed container"
print "Your Equipment is", equipment
print "Do you want to open the container? Yes or No"
container = raw_input("> ")
if "Yes" in container:
open_container()
else:
print "You left it alone"
elif "Overwatch" in do:
print "Orks Attack!!!"
enemy_attack()
elif "Hunt" in do:
print "You attack the Orks"
you_attack()
else:
print "The planetoid swallows you whole, and adds your mass to it!!"
exit(0)