豆豉鲮鱼罐头 2020-08-30 16:07 采纳率: 50%
浏览 73
已采纳

【急】【Python入门】 作业纠错 (为啥显示syntax error)?题目如图 我写的代码如下

图片说明

那个啥 图片照错了 题目里面没有说要用 “%f” 求给个不用"%f"的码。
"Your code will be provided an unknown value for x. (That is, don't specify x yourself.)

Write an if/elif/else statement which implements this piecewise expression and prints the result in the format 'x N'. Assume that the provided value is called x."

我写的代码如下:

if x < -1:
    x_N = 0
    print (x_N)
elif x>= -1 & x<=0 :
    x_N = 1+x
    print (x_N)
elif x>= 0 & x<=1 :
    x_N = 1-x
    print (x_N)
else:
    x_N = 0
    print (x_N)
  • 写回答

4条回答 默认 最新

  • threenewbee 2020-08-31 00:46
    关注

    elif x>= -1 & x<=0 :
    这里用 and 而不是 &
    别的地方类似

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?