I'm trying to validate that a user input int is numbers only. This has been my most recent try:
while True:
NumCars = int(input("Enter the number of cars on the policy: "))
NumCarsStr = str(NumCars)
if NumCarsStr == "":
print("Number of cars cannot be blank. Please re-enter.")
elif NumCarsStr.isalpha == True:
print("Number of cars must be numbers only. Please re-enter.")
else:
break
With this, I get the following error:
line 91, in <module>
NumCars = int(input("Enter the number of cars on the policy: "))
ValueError: invalid literal for int() with base 10: 'g'
(I entered a "g" to test if it was working) Thanks in advance!