New to python so forgive the basic question!
Ι am asking user a series of questions in this loop and assigning each answer to a variable to be used later in my script.
I’m also doing some error handling if the user doesnt enter an integer as response but not sure how to get it to repeat the relevant question if the user enters invalid input
questions = ['Please enter your gross annual salary: ', 'Please enter the annual amount of any bonus or commision that appears on your paylip. If not applicable enter 0: ', 'Please enter the annual amount of any benefits in kind that appear on your payslip. If not applicable enter 0: ', 'Please enter your annual total tax credit: ', 'Please enter your annual total pension contribution. If not applicable enter 0: ', 'Do you have any other non tax deductable income? (ie. Holiday purchase schemes etc.) If not applicable enter 0: ']
variables = ['salary', 'bonus', 'bik', 'tax_credits', 'pension contributions', 'other_non_tax_deductibles']
for question, variable in zip(questions, variables):
try:
variable = float(input({question}))
except ValueError:
print("Please enter a number")
else:
print(variable)