title: How can I detect if the user input is not an integer?
body: <p>I'm trying to make a small game using Python3. There are 3 options in the said game giving the user the option to input '1' '2' or '3', right now if anything other than an integer is inputted it crashes with the message:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;main.py&quot;, line 62, in &lt;module&gt;
      user_choice = int(input(&quot;&quot;&quot;
  ValueError: invalid literal for int() with base 10: 'fj
  </code></pre>
  <p>For reference heres the code i've been trying:</p>
  <pre><code> while i &lt; round_select: #Loops for value of round_select
    i += 1 #adds value to round_select every round until user input met
  
    opponent = random.randint(1,3)   #generates random integer printed as paper, scissors, or rock by above function
  
    
  
      time.sleep (0.2)
        user_choice = int(input(&quot;&quot;&quot;
        (1)Paper, (2)Scissors, (3)Rock!: &quot;&quot;&quot;))
  
        if user_choice == opponent:
          print (username + choice_to_text(user_choice)) 
          print (&quot;Opponent&quot; + choice_to_text(opponent)) 
          print (&quot;Tie&quot;)
          ties += 1 
        elif (user_choice == 1 and opponent == 2)  or (user_choice == 2 and opponent == 3) or (user_choice == 3 and opponent == 1): #outcomes grouped together to avoid mountains of elif statements
          print (username +  choice_to_text(user_choice))
          print (&quot;Opponent&quot;  + choice_to_text(opponent))
          print (&quot;One point to the opponent!&quot;)
          opponent_score += 1
        elif (user_choice == 1 and opponent == 3) or (user_choice == 2 and opponent == 1) or (user_choice == 3 and opponent == 2):
          print (username + choice_to_text(user_choice))
          print (&quot;Opponent&quot; + choice_to_text(opponent))
          print (&quot;One point to &quot; + (username) + &quot;!&quot;)
          user_score += 1
        elif user_choice != int or user_choice == ValueError:
          print (&quot;Please type an integer between 1 and 3 &quot;)
          i -= 1
  </code></pre>
  <p>edit:
  Looked like some people were trying to point me towards another question <a href="https://stackoverflow.com/questions/5424716/how-to-check-if-string-input-is-a-number">(How to check if string input is a number)</a>. I went to this before posting the question and couldn't find anything helping out so i went to write this.
  Thank you though to everyone who tried to help , It is working now :)</p>