I created a program in which the user enters a number, and the program will count up to that number and display how much time it took. However, when I enter letters or decimals (i.e. 0.5), I get an error. Here is the complete error message:
Traceback (most recent call last):
File "C:\Documents and Settings\Username\Desktop\test6.py", line 5, in <module>
z = int(z)
ValueError: invalid literal for int() with base 10: 'df'
What can I do to fix this?
Here is the complete 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 < z:
x = x + 1
print(x)
end_time = time.time()
diff = end_time - start_time
print("That took",(diff),"seconds.")
Please, help!
source
share