I have some code that is asking users questions and storing the responses in a list. I then want to assign the response values to variables from a list. Its not working as expected though as it doesnt look like the variables exist when I try and use them later in my script. I’ve seen a few similar questions on here and tried a few things out but nothing is working
<code>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']
responses = []
for question in questions:
while True:
try:
response = float(input({question}))
except ValueError:
print("Please enter a number")
else:
responses.append(response)
break
for variable, response in zip(variables, responses):
variable = response
</code>
<code>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']
responses = []
for question in questions:
while True:
try:
response = float(input({question}))
except ValueError:
print("Please enter a number")
else:
responses.append(response)
break
for variable, response in zip(variables, responses):
variable = response
</code>
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']
responses = []
for question in questions:
while True:
try:
response = float(input({question}))
except ValueError:
print("Please enter a number")
else:
responses.append(response)
break
for variable, response in zip(variables, responses):
variable = response