# 无法弄清楚如何打印以下输出

[英]Can't figure out how to print the following outputs

``````Income: 6100
Lowest tax: 1540.0
1540.0
Norway

Income: 9000
Lowest tax: 2340.0
2340.0
``````

``````Income: 1000000
Lowest tax: 150000.0
USA
Income: 6000
Lowest tax: 1500.0
Denmark Norway USA
Income: -1
``````

``````continue_input = True
income = 0

while continue_input :
income = int(input('Income: '))

if income < 0 :
continue_input = not True

# Norway
if income > 3000:
norway_tax1 = 0.1 * 3000
tax_left = income - 3000
norway_tax2 = 0.4 * tax_left
norway_tax = norway_tax1 + norway_tax2
elif income <= 3000:
norway_tax = 0.1 * income

# Denmark
denmark_tax = 0
percent = 0
for _ in range(int(income/1000)):
denmark_tax += percent * 1000
percent += 0.1
denmark_tax += percent * (income%1000)

# USA
if income <= 1500:
USA_tax = 0.12 * income
elif income > 1500 and income <= 6000:
USA_tax = 0.25 * income
elif income > 6000 and income <= 10000:
USA_tax = 0.38 * income
elif income > 10000:
USA_tax = 0.15 * income

min_tax = min(canada, norway_tax, USA_tax, denmark_tax)
print(f'Lowest tax: {min_tax}')
print(min_tax)

if min_tax == denmark_tax :
print('Denmark')

if min_tax == norway_tax :
print('Norway')

if min_tax == USA_tax :
print('USA')
print()
``````
1. 如果收入 < 0，您想立即跳出 while 循环，因此：

如果收入 < 0：中断

2. 删除行`print(min_tax)` ，它会额外打印 min_tax 。

3. 要将国家名称全部放在同一行，请执行以下操作：

``````    if min_tax == canada :

if min_tax == denmark_tax :
print('Denmark', end=" ")

if min_tax == norway_tax :
print('Norway', end=" ")

if min_tax == USA_tax :
print('USA', end=" ")

print()
``````

`end=" "`添加到`print()`将阻止它添加换行符。 它将添加一个空格。