跳过如果在Python中使用Statement / unstripped输入数据

Skipped If Statement/unstripped input data in Python

我正在更新我在Python中制作的代码游戏,以便您可以针对计算机玩单人游戏。 由于某种原因,解释器要么不使用从用于确定播放器计数的输入中剥离的数据,要么跳过使用来自输入的剥离数据的if语句。 无论哪种方式,在您输入玩家编号后,它会直接进入猜测代码,并带有正确代码字符的空列表。

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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永远是假的。 与plyrs == 1相同,这在整个过程中都是错误的。