0

After randomly generating a number, I check to see if the user's input matches. If it does, print one line, if not, print another. Even if the user guesses correctly, the other line prints.

chosenNumber = input ("Choose a number: ")
int (chosenNumber)
diceRoll = random.randint (1,3)
print ("The number rolled is: ",diceRoll)
if diceRoll == chosenNumber:
      print ("WINNER")
else:
      print ("LOSER")

Thank you for any help.

2
  • What's your question? What happens, and what were you expecting to happen? (Also, int(chosenNumber) won't do anything useful if you don't store the integer anywhere.) Commented Aug 22, 2013 at 0:03
  • 1
    Kudos for knowing that you can't compare a string to an integer and that you have to use int() :) Commented Aug 22, 2013 at 0:05

1 Answer 1

3

int() does not turn the string to an integer in place because strings are immutable.

You can do:

chosenNumber = int(input ("Choose a number: "))
Sign up to request clarification or add additional context in comments.

1 Comment

That worked! Thanks! I knew I could cast it to an int. At first I had chosenNumber = input (int("Choose a number: ")).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.