我不知道为什么这不起作用,它说p1_move1没有定义,但它位于顶部。
import random
p1_move1 = '0'
p1_move2 = '0'
p1_move3 = '0'
p1_move4 = '0'
player1pokemonchoice = '1'
player1pokemonhealth = 1000
cpupokemonhealth = 1000
if player1pokemonchoice == '1':
print ('''ATTACKS:
1. RKO - Damage 100 - 200
2. NATURE SLAM - Damage 100 - 200
3. GREEN ATTACK - Damage 100 - 200
4. NATURE GROTH - Damage 100 - 200''')
while player1pokemonchoice == '1' and player1pokemonhealth>=0 and cpupokemonhealth>=0:
p1_move = int(input('Which move would you like to choose?'))
if p1_move == 1:
p1_move1 = random.randint(100, 200)
cpupokemonhealth = cpupokemonhealth - pl_move1
print (p1_move1, "was dealt to the CPU's pokemon. His health is", cpupokemonhealth)
elif p1_move == 2:
p1_move2 = random.randint(100, 200)
cpupokemonhealth = cpupokemonhealth - pl_move2
print (p1_move2, "was dealt to the CPU's pokemon. His health is", cpupokemonhealth)
elif p1_move == 3:
p1_move3 = random.randint(100, 200)
cpupokemonhealth = cpupokemonhealth - pl_move3
print (p1_move3, "was dealt to the CPU's pokemon. His health is", cpupokemonhealth)
elif p1_move == 4:
p1_move4 = random.randint(100, 200)
cpupokemonhealth = cpupokemonhealth - pl_move4
print (p1_move4, "was dealt to the CPU's pokemon. His health is", cpupokemonhealth)
答案 0 :(得分:0)
在while
循环的每个减法行中,p1_move1 (or 2 or 3 or 4)
实际上是pl(那是“L”,而不是1)
答案 1 :(得分:0)
你在逗号之间加上整数,并且有一些拼写错误,而不是你键入pl的p1。所以试试这个
import random
p1_move1 = 0
p1_move2 = 0
p1_move3 = 0
p1_move4 = 0
player1pokemonchoice = 1
player1pokemonhealth = 1000
cpupokemonhealth = 1000
if player1pokemonchoice == 1:
print ('''ATTACKS:
1. RKO - Damage 100 - 200
2. NATURE SLAM - Damage 100 - 200
3. GREEN ATTACK - Damage 100 - 200
4. NATURE GROTH - Damage 100 - 200''')
while player1pokemonchoice == 1 and player1pokemonhealth>=0 and
cpupokemonhealth>=0:
p1_move = int(raw_input('Which move would you like to choose?'))
if p1_move == 1:
p1_move1 = random.randint(100, 200)
cpupokemonhealth = cpupokemonhealth - p1_move1
print (p1_move1, "was dealt to the CPU's pokemon. His health is", cpupokemonhealth)
elif p1_move == 2:
p1_move2 = random.randint(100, 200)
cpupokemonhealth = cpupokemonhealth - p1_move2
print (p1_move2, "was dealt to the CPU's pokemon. His health is", cpupokemonhealth)
elif p1_move == 3:
p1_move3 = random.randint(100, 200)
cpupokemonhealth = cpupokemonhealth - p1_move3
print (p1_move3, "was dealt to the CPU's pokemon. His health is", cpupokemonhealth)
elif p1_move == 4:
p1_move4 = random.randint(100, 200)
cpupokemonhealth = cpupokemonhealth - p1_move4
print (p1_move4, "was dealt to the CPU's pokemon. His health is", cpupokemonhealth)