-1

第一次发帖,试图把我的头包裹在 python 上,我正在解决一个编程问题,要求一名女售货员的佣金。由于某种原因,我无法显示总佣金,浮动如何影响最终结果?谢谢您的帮助。到目前为止,这是我的代码

#input for a sales womans sales per month in dollars, and her comission as a percent
#output comission for the month, need to convert percent to a decimal
#variables: Salesamount (float), comission rate(float) comssisoin earned (float)
#formula: comission earned = sales amount * (comissionrate/100)
print " This program will compute the comission earned for the month based on your sales for the month."
comission_rate = input("what is your comission rate percent? ") 
sales = raw_input("How many sales did you have this month? ")
total_com = sales * (comission_rate / 100)
print " your total comission for the month is "
print total_com
4

1 回答 1

1

您需要将所有输入值转换为浮点数:

print "This program will compute the comission earned for the month based on your sales for the month."
comission_rate = float(raw_input("what is your comission rate percent? "))
sales = float(raw_input("How many sales did you have this month? "))
total_com = sales * (comission_rate / 100)
print " your total comission for the month is "
print total_com

(错误输入的异常处理留给读者练习)

于 2013-09-20T15:01:38.810 回答