У меня есть код, который задает пользователям вопросы и сохраняет ответы в списке. Затем я хочу присвоить значения ответа переменным из списка. Однако это не работает так, как ожидалось, поскольку не похоже, что переменные существуют, когда я пытаюсь использовать их позже в своем скрипте. Я видел здесь несколько похожих вопросов и пробовал кое-что, но ничего не работает
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
Подробнее здесь: https://stackoverflow.com/questions/786 ... -in-python