Python 2.7 我需要做到最好的五分之三,但我可以';如果代码不能返回分数,我该怎么办?

Python 2.7 我需要做到最好的五分之三,但我可以';如果代码不能返回分数,我该怎么办?,python-2.7,counter,Python 2.7,Counter,为了详细说明我的要求,我需要制作一个计数器,使我能够以3/5的比赛决定两个对手(基本上是一场石头剪刀游戏)的胜者。我将代码设置为返回winners score+1,但无论谁赢,结果都是0/0,我不知道如何解决我遇到的任何问题 # Pkemon python 2.7.11 import random # pokemon list / attack pokemon = ["pikachu", "Squirtle", "Arbok", "Butterfree", "Ekans", "Spe

为了详细说明我的要求,我需要制作一个计数器,使我能够以3/5的比赛决定两个对手(基本上是一场石头剪刀游戏)的胜者。我将代码设置为返回winners score+1,但无论谁赢,结果都是0/0,我不知道如何解决我遇到的任何问题

#  Pkemon python 2.7.11    

import random
# pokemon list / attack
pokemon = ["pikachu", "Squirtle", "Arbok", "Butterfree", "Ekans", "Spearow","Xerneas","Zygarde","Timburr","Kangaskhan","Buizel","Abomasnow","Bergmite","Braviary","Burmy","Chandelure","Cofagrigus","Crawdaunt","Conkeldurr","Crustle","Cryogonal","Darkrai","Dewgong","Dragonite","Dunsparce","Dwebble","Empoleon","Foongus","Gardevoir"]    

# important things
def select_random(pokemon):
    pokepick = random.choice(pokemon)
    return pokepick
#the attacks
Attack = ["Air", "Water", "Grass"]
# Score/attack
def poke_score():
    score = random.choice(Attack)
    return score    

# things
user_poke = select_random(pokemon)
enemy_poke = select_random(pokemon)
enemy_score = poke_score()    

#staging
print "5 matches Best 3 out of 5"
print user_poke,"Vs.",enemy_poke
print "Select Attack"    

# user select attack
def make_score():
    score = raw_input("Air Water or Grass")
    return score
user_score = make_score()    

# outputs and battle sequence
def battle():
    etal = 0
    utal = 0
    print "current score", utal,"/",etal
    if user_score == "Air" and enemy_score == "Grass":
        etal = etal + 1
        print enemy_poke, "used", enemy_score, user_poke, "used", user_score, enemy_poke, "Match Won!"
        return etal    

    elif user_score == "Grass" and enemy_score == "Water":
        etal = etal + 1
        print enemy_poke, "used", enemy_score, user_poke, "used", user_score, enemy_poke, "Match Won!"
        return etal
    elif user_score == "Water" and enemy_score == "Air":
        etal = etal + 1
        print enemy_poke, "used", enemy_score, user_poke, "used", user_score, enemy_poke, "Match Won!"
        return etal    

    elif user_score == enemy_score:
        print enemy_poke, "used", enemy_score, user_poke, "used", user_score, "Match was a Tie!!"
# forfeits match if no attack or incorrect attack is given
    elif user_score != "Air" "Water" "Grass":
        etal = etal + 1
        print user_poke, "Forfeits!", enemy_poke, "Wins!"
        return etal    

    else:
        utal = utal + 1
        print enemy_poke, "used", enemy_score, user_poke, "used", user_score, user_poke, "Match Won!"
        return utal    

battle()

实际上,在为每个打印构造添加括号并替换一些语句后,您的代码对我来说运行良好


更新)

在“查看器”中,标签有多少空格?这个问题不清楚,请在问题文本中对问题进行更详细的描述。4空格,为了详细说明我的问题,我需要制作一个计数器,让我能够决定两个对手的获胜者(基本上是一个石头剪刀游戏)在3/5场比赛之前,我将代码设置为返回赢家分数+1,但无论谁赢,结果都是0/0,我不知道如何解决我遇到的任何问题。演示将此错误回溯(最近一次调用):文件“python”,第30行,在文件“python”中“,第28行,在make_score NameError:name'raw_input'未定义我怀疑演示是在python 3中的原因,我正在2.7.11中编写代码,我尝试了您在我自己的编辑器中所说的,但我仍然遇到代码未保留分数的相同问题。@trey您提到的这些错误是因为raw_input()在python3中已更改为input(),并且计数器将永远不会增加,因为每次调用该函数时,该函数都会将其返回为零,因此让return语句之前的打印以及“etal”和“utal”增加之后的打印、、、、请参阅更新后的演示–啊,好的,我现在看到了,如果不明显,我是python thx的新手,需要帮助