Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.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_Python 3.x - Fatal编程技术网

Python 我总是一无所获

Python 我总是一无所获,python,python-3.x,Python,Python 3.x,我的代码: def get_feedback(mark, out_of): percentage = int((mark / out_of) * 100) if percentage >= 80: print("Excellent") if 60 < percentage < 70: print("Good") if 50 < percentage < 59: print("Pass"

我的代码:

def get_feedback(mark, out_of):
    percentage = int((mark / out_of) * 100)

    if percentage >= 80:
        print("Excellent")
    if 60 < percentage < 70:
        print("Good")
    if 50 < percentage < 59:
        print("Pass")
    if percentage < 50:
        print("Not a pass")
def获取反馈(标记,超出):
百分比=整数((标记/不标记)*100)
如果百分比>=80:
打印(“优秀”)
如果60<百分比<70:
打印(“好”)
如果50<百分比<59:
打印(“通行证”)
如果百分比<50:
打印(“非通行证”)

我知道我必须在某个地方使用return语句,但我不确定它是如何工作的,也不确定何时使用它。如果有人能帮忙,那就太好了,谢谢

使用退货代替打印。示例:-返回“极好”。

您可以创建一个变量来表示其条件的值

def get_feedback(mark, out_of):
    percentage = int((mark / out_of) * 100)

    if percentage >= 80:
        feedback = "Excellent"
    elif 60 < percentage < 70:
        feedback = "Good"
    elif 50 < percentage < 59:
        feedback = "Pass"
    elif percentage < 50:
        feedback = "Not a pass"

    return print(feedback)
def获取反馈(标记,超出):
百分比=整数((标记/不标记)*100)
如果百分比>=80:
反馈=“非常好”
elif 60<百分比<70:
反馈=“好”
elif 50<百分比<59:
反馈=“通过”
elif百分比<50:
反馈=“不是通行证”
返回打印(反馈)
最后,我们使用return给出函数的结果。另外,请注意,我使用了elif语句,这比只使用if语句要快。

def get\u feedback(mark,out\u of):
def get_feedback(mark, out_of):
    percentage = int((mark / out_of) * 100)
    remark = ''
    if percentage >= 80:
        remark = "Excellent"
    elif 60 <= percentage <= 79:
        remark = "Good"
    elif 50 <= percentage <= 59:
        remark = "Pass"
    else percentage < 50:
        remark = "Not a pass"
    return remark
百分比=整数((标记/不标记)*100) 备注=“” 如果百分比>=80: 备注=“非常好”
elif 60另一种方法:

def get_feedback(mark, out_of):
    percentage = int((mark / out_of) * 100)

    if percentage >= 80:
        return "Excellent"
    elif 60 <= percentage <= 79:
        return "Good"
    elif 50 <= percentage <= 59:
        return "Pass"
    else:
        return "Not a pass"
def获取反馈(标记,超出):
百分比=整数((标记/不标记)*100)
如果百分比>=80:
返回“优秀”

elif 60而不是
打印(“优秀”)
等。使用
grade='Excellent'
等,并在结尾处使用
返回等级
。请注意,您丢失了一个70到79岁马克的案例。这有帮助吗@琥珀树林