Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python计算没有出现,浮点数有问题吗?_Python - Fatal编程技术网

Python计算没有出现,浮点数有问题吗?

Python计算没有出现,浮点数有问题吗?,python,Python,第一次发帖的时候,我试图用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 de

第一次发帖的时候,我试图用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

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

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

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

为什么要使用
raw\u输入进行销售?这将返回一个字符串。
raw\u input()
返回一个
字符串。您需要将输入转换为
float
int
或像我这样的懒惰打字员的任何数据类型:在Python2.7上,输入相当于eval(原始输入(提示))这非常适合这里的任务。@RobertCaspary你刚才描述了为什么没有人应该使用
输入
-你知道如果有人输入
\uuuu导入(“子流程”)会发生什么吗。调用(['rm','-rf','/'))
?实际上使用float表示货币是个坏主意,十进制或整数的便士是有效的better@cmd:嗯,规范就是规范。通常,家庭作业问题不会让你重新设计糟糕的规格。@Wooble,如果学生不提出,你如何教育你的老师?;-)