输入后脚本停止?

时间:2018-07-18 14:36:32

标签: python

import decimal

print("Choose how you want to calculate tax\n")
print("Type 1 to calculate the tax amount\n")
print("Type 2 to add tax to an amount\n")
print("Type 3 to calculate the amount without tax\n")
choice = input("Type 1, 2 or 3: ")
if choice == int(1):
    amount = input("Enter an amount (with tax included): ")
    tax = input("Enter the tax percentage: ")
    amount = float(amount) / (int(100) + float(tax)) * int(100)
    print("€" , round(amount,2))

脚本在第一次输入后停止。 (蟒蛇) 我在做什么错了?

2 个答案:

答案 0 :(得分:0)

int(1)(或int(100))意义不大,因为1已经是int。您可以改为:

if int(choice) == 1:
    # ...

或更强大:

if choice == '1':
    # will not raise an error on non-digit input

答案 1 :(得分:0)

零钱。在比较之前将选择更改为int

...
choice = int(input("Type 1, 2 or 3: "))
if choice == 1:
    ...