需要将用户输入数据转换为百分比并添加到总和变量 Python 3.6
Need user input data converted as percentage and added to a total sum variable Python 3.6
如何将以整数形式收集的用户输入数据转换为百分比,然后将转换后的百分比数据转换为存储在变量中的 运行 总和?我需要将 "Tax percentage to be collected" 输入数据转换成百分比并以某种方式添加到 "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
同样,我需要 "Tax percentage to be collected" 输入问题数据,该数据以整数形式收集并转换为百分比并添加到 运行 总计 "t" 变量中。
首先,我将从使代码更具可读性开始:
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
你是说
t = 0
t += int(input("Processing fee"))
t += t / 100 * int(input("Tax percentage to be collected"))
?我不确定我是否完全理解你的问题。
如何将以整数形式收集的用户输入数据转换为百分比,然后将转换后的百分比数据转换为存储在变量中的 运行 总和?我需要将 "Tax percentage to be collected" 输入数据转换成百分比并以某种方式添加到 "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
同样,我需要 "Tax percentage to be collected" 输入问题数据,该数据以整数形式收集并转换为百分比并添加到 运行 总计 "t" 变量中。
首先,我将从使代码更具可读性开始:
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
你是说
t = 0
t += int(input("Processing fee"))
t += t / 100 * int(input("Tax percentage to be collected"))
?我不确定我是否完全理解你的问题。