ユーザが印刷するために「いいえ」と入力した場合(M1)、最後の印刷文が実行されないようにするにはどうすればよいですか?私はM1が印刷されるときにプログラムを終了させたい。私はエラーを受け取ります "NameError:name 'TaxCode'がブロック内に宣言されているため、ユーザーが 'no'を入力したときに 'TaxCode'が定義されていません。 ありがとうございます。コマンドが実行されないようにする
name = input("What is your name? ")
while True:
try:
income = int(input("What is your income? ($) "))
break
except ValueError:
print ("Invalid input\nPlease enter a figure")
continue
else:
break
M1 = "This program cannot determine your tax code. Please use the program for secondary income "
print("Please answer the questions with 'yes' and 'no'")
Q1=input("Do you receive an income tested benefit? ")
while Q1 != "yes" and Q1 != "no":
print("\nPlease enter either 'yes' or 'no'")
Q1=input("Do you recieve an income tested benefit? ")
if Q1=="yes":
Q2=input("Is this tax code for the income tested benefit? ")
while Q2 != "yes" and Q2 != "no":
print("\nPlease enter either 'yes' or 'no'")
Q2=input("Is this tax code for the income tested benefit? ")
if Q2=="yes":
TaxCode = "M"
elif Q2=="no":
print (M1)
print("Thanks for answering the questions.",name,"Your tax code is ",TaxCode)
提供されている解決策のいずれかが問題を解決する場合は、回答として受け入れるか、助けてください。人々はあなたの問題を解決するのに時間を費やします。 – Mani