a-树 发表于 2018-10-22 16:07:31

如何saygoodbye

编写程序,先输入两个整数,然后提示用户输入这两个整数的和。如果答案正确,程序报告结果true;
否则,报告false。 输入两个加数,一个结果,直到输入两个0为止 。
Sample Input
20 5 100
15 5 50
17 27 44
0 0
Sample Output
false
false
true
红色字体是我的问题——下面时我打的代码,就差那个了!!!
x,y,z = map(int,input().split())
while x!=0 and y!=0:
    if x+y ==z:
      print('true')
      x,y,z = map(int,input().split())
    else:
      print('false')
      x,y,z = map(int,input().split())

claws0n 发表于 2018-10-22 16:32:04

x, y = 1, 1
while x!=0 and y!=0:
    stdin = input().split()
    if len(stdin) == 2:
      break
    else:
      x,y,z = map(int,stdin)
      if x+y ==z:
            print('true')
      else:
            print('false')

claws0n 发表于 2018-10-22 16:34:56

没有安全检查while 1:
    stdin = input().split()
    if stdin == '0' and stdin == '0':
      break
    else:
      x,y,z = map(int,stdin)
      if x+y ==z:
            print('true')
      else:
            print('false')

塔利班 发表于 2018-10-22 16:48:39

while 1:
    t= input().split()
    if t == '0' and t == '0' and len(t)==2:
      break
    else:
      x,y,z = map(int,t)
      if x+y ==z:
            print('true')
      else:
            print('false')
copy楼上的,但是0 0 0不该退出

a-树 发表于 2018-10-22 16:59:49

塔利班 发表于 2018-10-22 16:48
copy楼上的,但是0 0 0不该退出

是滴是滴,更严密{:5_108:}
页: [1]
查看完整版本: 如何saygoodbye