为什么我的测试用例失败,即使我的代码看起来正确

时间:2019-05-27 03:00:40

标签: python python-3.x

从STDIN读取输入。将输出打印到STDOUT'''

使用input()从STDIN读取输入,并使用print将输出写入STDOUT

def main():
    num1 = int(902)
    num2 = int(100)
    num3 = int(666)

    if (num1 > num2) and (num1 > num3):    
        largest = num1
    elif (num2 > num1) and (num2 > num3):    
        largest = num2
    else:
        largest = num3
    print("The largest number is",largest)

main()

enter image description here

即使我的代码正确,我在Techgig Practice Test上的测试用例结果也显示失败,尽管我得到了正确的输出。在这种情况下,我应该一直解决这个问题。没有一个问题表明我通过了测试案例。

1 个答案:

答案 0 :(得分:0)

尝试:-

def main():
    num1 = int(input())
    num2 = int(input())
    num3 = int(input())

    for x in (num1, num2, num3):
        if x not in range(-100000, 100001):
            print("Error! Numbers should be between -100000 and 100000.")
            exit()

    if (num1 > num2) and (num1 > num3):    
        largest = num1
    elif (num2 > num1) and (num2 > num3):    
        largest = num2
    else:
        largest = num3
    print(largest)

main()