Oct-04-2018, 07:36 PM
It looks like you're already doing some validation:
(Oct-04-2018, 07:05 PM)ccm1776 Wrote:The only thing you don't check first, is the salary. In that case, try a while loop to keep asking until a valid salary is given. Check this out:if employeeState in lowTaxStates: stateTaxes= 0.10*employeeSalary else: stateTaxes=0.12*employeeSalary
>>> valid = False >>> while not valid: ... salary = input("Employee's salary: ") ... try: ... salary = float(salary) ... valid = True ... except ValueError: ... print("That's not a valid value for salary. Please try again.") ... Employee's salary: fish That's not a valid value for salary. Please try again. Employee's salary: $43,000.50 That's not a valid value for salary. Please try again. Employee's salary: 43000.50 >>> salary 43000.5