0

I'm updating a crack the code game I made in Python so that you can play a single-player game against the computer. For some reason, the interpreter either doesn't use the data stripped from the input used to determine player count or skips the if statement that uses the stripped data from the input. Either way, after you input the player number it goes straight to the guessing code with an empty list of correct code characters.

My code for the player count determining and code creation is:

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('')

No other skipping if statement questions apply to this so please help.

1 Answer 1

2

plyrs is a string, and you're comparing it to an int. "2" == 2 will always be false. Same with plyrs == 1, this will be false throughout.

Sign up to request clarification or add additional context in comments.

4 Comments

How would I turn it into a int? I used the int() function on the input so either that isn't a correct answer or I'm doing something wrong
nvm I used str() for some reason
You'll need to raise a ValueError if you want to safely handle bad inputs (non-numerical inputs)
Here is a link to help you with that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.