这就是问题所在。
编写程序以解决简单的工资核算。查找给定的工资额,工作小时数和每小时费率。 (计算工资单的公式是工资=小时工资*工作小时数。)
What i have so far def hours(): 小时=输入(“你工作了几个小时?:”) 返回时间
def rate():
rate= input("How much is your hourly rate?: ")
def grossPay():
grossPay = hours() * rate()
return grossPay
def main():
print("your gross pay is"), + (grossPay)
return grossPay
def main():
print('Payroll Information')
print hours()
print rate()
main()
答案 0 :(得分:0)
代码存在一些问题......
有很多方法可以做到这一点,但把它全部放在一个函数中对我来说是最自然的。我会做这样的事......
def calc_and_show_pay():
rate = input("How much is your hourly rate?: ") #collect the hourly rate
hours = input("How many hours did you work?: ") #collect number of hours worked
gross_pay = float(rate) * float(hours) #Convert string input to floats so we can do math on it
print("Payroll Information:") #print out results, per your format in the example
print("Your pay is %f"%(gross_pay)) #could also do print("your pay is:", gross_pay)
return gross_pay #you don't need to return this unless you want to use this number elsewhere (i.e., you have a bigger program where you'll use this as an input somewhere else).
然后你可以随意调用“calc_and_show_pay()”。