title: ValueError: invalid literal for int() with base 10 -- how to guard against invalid user input?
body: <p>I made a program where the user enters a number, and the program would count up to that number and display how much time it took. However, whenever I enter letters or decimals (i.e. 0.5), I would get a error. Here is the full error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Documents and Settings\Username\Desktop\test6.py", line 5, in &lt;module&gt;
      z = int(z)
  ValueError: invalid literal for int() with base 10: 'df'
  </code></pre>
  
  <p>What can I do to fix this?</p>
  
  <p>Here is the full code:</p>
  
  <pre><code>import time
  x = 0
  print("This program will count up to a number you choose.")
  z = input("Enter a number.\n")
  z = int(z)
  start_time = time.time()
  while x &lt; z:
      x = x + 1
      print(x)
  end_time = time.time()
  diff = end_time - start_time
  print("That took",(diff),"seconds.")
  </code></pre>
  
  <p>Please help!</p>