答案为什么是0啊难道不是3吗

img

函数f在x=10时 执行

elif  10 <= x < 20:
    print(0.5 * x - 2)

即答案为 0.5*10-2=3
所以你的答案是正确的,原题目给的答案出错了

怎么可能是0,题目答案错了吧
一模一样的代码,运行了 你看一下 3呀

img

def f(x):
    if x < 0 or x >= 20:
        print(0)
    elif 0<=x<5:
        print(x)
    elif 5<=x<10:
        print(3*x-5)
    elif 10<=x<20:
        print(0.5*x-2)
f(10)

相信自己,加油!

if条件要用and

             if x<0 or x>=20
                         print(0elif 0<=x and x<5:
                        print(x)
             elif 5<=x and x<10
                       print3*x-5elif 10<=x and x<20:
                      print0.5*×-2

是3啊,你从哪儿看的答案是0了