0

I'm working on a personal project that does the math to figure out what my paychecks should be given taxes, hours worked, etc. and so far it works. But I wanted to take it a step further to detect if the user has made a typo and entered letters, like "alkfdflkjad" instead of actual numbers when asked for the number of hours worked.

I've tried a couple different variations of if-else statements but they always give me an error instead of running the else prompt like "Please check your input!" My most recent code had this:

hours=float(input("Enter number of hours worked: "))

if hours.isdigit():
    gross_pay=(hours*pay_rate)
else:
    print(“Please enter a number.”)
John Gordon
  • 29,573
  • 7
  • 33
  • 58
Moko
  • 1
  • `while True:` / `hours = input(...)` / `if hours.isdigit():` / `break` / `print("Please enter a number")`. Now, outside the loop, you know you have digits. – Tim Roberts Feb 06 '23 at 00:03

0 Answers0