Why is no ValueError raised on this try / except when isalpha should fail.
I know that isalpha returns false if given a number
In [9]: ans = input("Enter a Letter")
Enter a Letter4
In [10]: ans.isalpha()
Out[10]: False
How do I get the value error if they supply a number instead of a y or n? Because if the try is false shouldn't it stop being true and not print my trajectory?
import sys
v0 = float(input("What velocity would you like? "))
g = float(input("What gravity would you like? "))
t = float(input("What time decimal would you like? "))
print("""
We have the following inputs.
v0 is %d
g is %d
t is %d
Is this correct? [Y/n]
""" % (v0, g, t))
while True:
try:
answer = input("\t >> ").isalpha()
print(v0 * t - 0.5 * g * t ** 2)
except ValueError as err:
print("Not a valid entry", err.answer)
sys.exit()
finally:
print("would you like another?")
break
For example if the user types 5 not a y or n still gets an answer
$ python3 ball.py
What velocity would you like? 2
What gravity would you like? 3
What time decimal would you like? 4
We have the following inputs.
v0 is 2
g is 3
t is 4
Is this correct? [Y/n]
>> 5
-16.0
would you like another?