需要将用户输入的数据转换为百分比并添加到total sum变量python3.6中

2024-04-29 14:32:59 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将作为整数收集的用户输入数据转换为百分比,然后将转换后的百分比数据转换为存储在变量中的运行总和?我需要将“要征收的税收百分比”输入数据转换为百分比,并以某种方式添加到“t”变量中。你知道吗

以下是我收集数据的方式:

b = 0
b += int(input("Acquisition cost?"))
b += int(input("Misc Expenses?"))

t = 0
t += int(input("Processing fee"))
t += int(input("Tax percentage to be collected"))

s = 0
s += int(input("Sell price?"))


net_profit =  (b + t) - s
cost_to_buyer = s + t

同样,我需要“要收集的税收百分比”输入问题数据,该数据作为一个整数收集,转换为百分比,并添加到运行的total“t”变量中。你知道吗


Tags: to数据用户input方式整数税收int
3条回答

你的意思是

t = 0
t += int(input("Processing fee"))
t += t / 100 * int(input("Tax percentage to be collected"))

什么?我不确定我是否完全理解你的问题。你知道吗

首先,我要让代码更具可读性:

acquisition_cost = int(input("Acquisition cost?"))
expenses = int(input("Misc Expenses?"))

total_cost = acquisition_cost + expenses 


tax = int(input("Processing fee"))
# Is this what you were looking for? 
tax_band = float(input("Tax percentage to be collected"))/100

total_tax = tax * tax_band


sell_price = int(input("Sell price?"))

net_profit = (total_cost + total_tax) - sell_price
cost_to_buyer = sell_price + total_tax

你可以用这样的方法:

t *= 1+int(input("Tax percentage to be collected"))/100

示例

t = 0
t += int(input("Processing fee")) # input 100
t *= 1+int(input("Tax percentage to be collected"))/100 # input 5

print(t) # result 105.0

相关问题 更多 >