RJL0302 2023-03-01 21:54 采纳率: 0%
浏览 10

PTA平台7—-29

PTA 7-29 优异生查询(类和对象)
上传后是非零返回 ,是为什么?


n = list(input().split())
m = list(map(int,input().split()))
c = list(map(int,input().split()))
e = list(map(int,input().split()))
n0 = m[0]+c[0]+e[0]
n1 = m[1]+c[1]+e[1]
n2 = m[2]+c[2]+e[2]
if n0>n1>n2 or n0>n2>n1:
    print(n[0],end=' ')
    print(m[0],c[0],e[0],end='')
if n1>n0>n2 or n1>n2>n0:
    print(n[1],end=' ')
    print(m[1],c[1],e[1],end='')
if n2>n1>n0 or n2>n1>n0:
    print(n[2],end=' ')
    print(m[2],c[2],e[2],end='')
  • 写回答

1条回答 默认 最新

  • Taylor 淡定哥 2023-03-02 03:59
    关注

    a>b>c这种形式的比较语句是有效的,但是在这个代码中,由于比较运算符的优先级问题,if n0>n1>n2 or n0>n2>n1:等语句实际上是被解释为(n0>n1)>n2 or (n0>n2)>n1,而不是n0>n1 and n1>n2,这会导致比较结果不符合预期。
    参考一下这个

    n = list(input().split())
    m = list(map(int,input().split()))
    c = list(map(int,input().split()))
    e = list(map(int,input().split()))
    n0 = m[0]+c[0]+e[0]
    n1 = m[1]+c[1]+e[1]
    n2 = m[2]+c[2]+e[2]
    if (n0>n1 and n1>n2) or (n0>n2 and n2>n1):
        print(n[0],end=' ')
        print(m[0],c[0],e[0],end='')
    if (n1>n0 and n0>n2) or (n1>n2 and n2>n0):
        print(n[1],end=' ')
        print(m[1],c[1],e[1],end='')
    if (n2>n1 and n1>n0) or (n2>n0 and n0>n1):
        print(n[2],end=' ')
        print(m[2],c[2],e[2],end='')
    
    
    
    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 3月1日

悬赏问题

  • ¥60 基于MATLAB的TAOD算法
  • ¥15 Groimp使用疑问
  • ¥15 MDK–ARM里一直找不到调试器
  • ¥15 oracle中sql查询问题
  • ¥15 vue使用gojs3.0版本,在nodeDataArray中的iconSrc使用gif本地路径,展示出来后动画是静态的,不是动态的
  • ¥100 代写个MATLAB代码,有偿
  • ¥15 ansys electronics 2021 R1安装报错,错误代码2,如图
  • ¥15 Dev-c++打字不出现中文,但出现日文
  • ¥30 搭建面包板由NE555N和SN74LS90N组成的计时电路时出了问题
  • ¥15 无源定位系统的时差估计误差标准差