Python 输入后脚本停止?

Python 输入后脚本停止?,python,Python,脚本在第一次输入后停止。(Python) 我做错了什么?int(1)(或int(100))毫无意义,因为1已经是int。您可以改为: 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

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

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

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))
或者更为稳健:

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

零钱。比较前将选项更改为
int

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

因为
input
返回一个
str
并且将
str
int(1)
进行比较(顺便说一下,
int
位是冗余的)总是
False
,所以您需要
如果choice='1':
或者将
输入转换为
int
,然后进行比较,即
choice=int(input…)
然后
如果选择==1:
谢谢大家:)
...
choice = int(input("Type 1, 2 or 3: "))
if choice == 1:
    ...