title: Python 3 - Error handling to calculator
body: <p>I'm doing a simple calculator in Python 3 for training purposes.</p>
  
  <p>This is where i'm at right now:</p>
  
  <pre><code>import math
  number1 = int(input("Give the first number: "))
  number2 = int(input("Give the second number: "))
  
  while True:
       print("(1) +\n(2) -\n(3) *\n(4) /\n(5) sin(number1/number2)\n(6)  cos(number1/number2)\n(7)Swap numbers\n(8)quit")
       print("Selected numbers:",number1,number2)
       selection = int(input("Choose (1-8): "))
       if selection == 1:
           print("The answer is:", number1+number2)
       elif selection == 2:
           print("The answer is:", number1-number2)
       elif selection == 3:
           print("The answer is:", number1*number2)
       elif selection == 4:
           print("The answer is:", number1/number2)
       elif selection == 5:
           print("The answer is:", math.sin(number1/number2))
       elif selection == 6:
           print("The answer is:", math.cos(number1/number2))
       elif selection == 7:
           number1 = int(input("Give new first number: "))
           number2 = int(input("Give new second number: "))
       elif selection == 8:
           break
       else:
           print("Invalid selection.") 
  </code></pre>
  
  <p>What i want to do now is to check the user input if it contains only numbers.
  If the input contained characters the program would print "Invalid input" or so and then it would ask for the numbers again (While loop?).
  Also in the selection i would like to check that the selection number is between 1 and 8, everything else would result in asking the numbers again.</p>
  
  <p>What i've heard this i can do with <code>try: ... except (TypeError, ValueError)</code>. But i can't manage to get it work. Do i need to think of rewriting my code?</p>