小编Nat*_*kes的帖子

Python-如何在 x 和 y 之间进行 if 语句?

我最近开始接触 Python,因为 C++ 很有趣,但 Python 似乎有点酷。只要输入在某个数字范围之间,我就想让 Python 做一些事情。

def main():
    grade = float(input("“What’s your grade?”\n:"))
    if grade >= 90:
        print("“You’re doing great!”")
    elif(78 >= grade <= 89):
        print("“You’re doing good!”")
    elif(77 >= grade > 65):
        print("You need some work")
    else:
        print("Contact your teacher")

main()
Run Code Online (Sandbox Code Playgroud)

当我在做 elif 语句时问题就出现了,我不能这样做,所以只要成绩在 65 到 89 之间,Python 只会打印“做得很好”的语句。你将如何处理数字范围?

python if-statement between numeric-ranges floating-point-comparison

5
推荐指数
1
解决办法
3万
查看次数