我的函数返回“无" [英] My function returns "None"

查看:63
本文介绍了我的函数返回“无"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 新手,我试图解决这个练习,但一直得到无"输出.该问题要求一个程序,其中输入是小时数和费率,输出是总工资,如果加班时间超过 40 小时,则包括加班费.无论如何,这是代码(我使用的是 Python 3.5.1):

I am new to Python and I was trying to solve this exercise, but keep getting 'None' output. The question asked for a program in which the input is hours and rate and the output is the gross pay, including overtime if it is more than 40 hours. Anyway, this is the code (I am using Python 3.5.1):

def compute_pay (h,r):
    if h <= 40:
        pay = h*r
        return


    elif h>40:
         pay = (((h-40)*1.5)*r+(40*r))
         return

hours = input ("Enter hours:")
rate= input ("Enter rate")
x = float (hours)
y = float (rate)
p = compute_pay (x,y)
print (p)

推荐答案

return 将返回 None 如果你不给它任何其他东西.试试退货

return will return None if you don't give it anything else. Try return pay

这篇关于我的函数返回“无"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆