跳过了If语句/取消了Python中的输入数据



我正在更新我用Python制作的破解代码游戏,这样你就可以在电脑上玩单人游戏了。出于某种原因,解释器要么不使用从输入中剥离的数据来确定玩家数量,要么跳过使用从输入剥离的数据的if语句。无论哪种方式,在输入玩家号码后,它都会直接进入猜测代码,其中包含一个空的正确代码字符列表。

我的玩家数量确定和代码创建代码是:

plyrs = 0
correctanswer = []
print('Welcome!')
plyrs = str(input('How many players are there? (minimum 1, maximum 2) '))
if plyrs == 2:
    print("I'm gonna ask you for some alphanumerical (number or letter characters to make a code for the other player to guess.")
    input('Press enter when you are ready to enter in the code!') #Like all of my games, it has a wait.
i = 0
    while i < 4:
        correctanswer.append(input('What would you like digit ' + str(i + 1) + " to be? "))
        i = i + 1
    print("Ok, you've got your code!")
    i = 0
    while i < 19: #Generates seperator to prevent cheating
        print('')
        i = i + 0.1
    print("Now, it's the other player's turn to guess!")
elif plyrs == 1:
    import random
    characters  = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0']
    i = 0
    while i < 4:
        correctanswer.append(characters[randint(0,36)])
        i = i + 1
    print('Time for you to guess!')
print('')

如果陈述问题适用于此,则没有其他跳过,因此请提供帮助。

plyrs是一个字符串,您将其与int进行比较。"2" == 2将始终为false。与plyrs == 1相同,这将始终为false。

最新更新