範囲が 70000 以上の for ループを作成するにはどうすればよいですか? 所得税の for ループを実行していますが、所得が 70000 を超えると 30% の税金がかかります。私は何かをしfor income in range(income-70000)
ますか?
最初はループを使用しないコードを開発し、問題なく動作しましたが、コードにループを組み込む必要があると通知されました。これは私が持っているものですが、for ループを使用する意味がありません。誰かが私を助けることができますか?
def tax(income):
for income in range(10001):
tax = 0
for income in range(10002,30001):
tax = income*(0.1) + tax
for income in range(30002,70001):
tax = income*(0.2) + tax
for income in range(70002,100000):
tax = income*(0.3) + tax
print (tax)
さて、while ループを試してみましたが、値が返されません。あなたの考えを教えてください。所得に基づいて所得税を計算する必要があります。最初の10000ドルは税金がありません。次の 20000 年には 10% です。次の 40000 には 20% があります。70000 を超えると 30% になります。
def taxes(income):
income >= 0
while True:
if income < 10000:
tax = 0
elif income > 10000 and income <= 30000:
tax = (income-10000)*(0.1)
elif income > 30000 and income <= 70000:
tax = (income-30000)*(0.2) + 2000
elif income > 70000:
tax = (income - 70000)*(0.3) + 10000
return tax