它说“薪水”没有定义,或者我不能把它乘以。 我想有它与def命令,所以请只是让它在这个形式只是纠正错误,我完全是新的,所以只是让它简单,因为它是。非常感谢:)
def computepay(Hours,RatePerHour):
if float(Hours)-40<0:
salary=float(Hours)*float(RatePerHour)
else:
salary=40.0*float(RatePerHour)+(float(Hours)-40.0)*float(RatePerHour*1.5)
Hours=input("Hours:\n")
RatePerHour=input("RatePerHour:\n")
computepay(Hours,RatePerHour)
print("Salary:")
print(salary)
我希望有人能帮助我这个小程序如何正确工作
您需要
return salary
,然后将其赋给一个变量。以下是代码的改进版本:您需要在这里学习的概念称为scope。你知道吗
你需要把计算出来的薪水还给我。你知道吗
另外,如果对输入执行浮点转换,则更简单。你知道吗
下面是更正,下面是一些说明。你知道吗
首先,salary是一个包含在函数中的变量,它在函数之外是不可用的。你知道吗
第二,你得到一个错误,因为你用一个整数乘一个字符串。之前将其转换为float。你知道吗
相关问题 更多 >
编程相关推荐