首页 > 解决方案 > 为什么在两行上写 int(input()) 与一行不同?

问题描述

我正在编写代码来解决 CodeChef 上的以下问题:https ://www.codechef.com/problems/HS08TEST/

问题本身并不重要,我的问题是我提交了两个答案:

1: 

x,y = input().split()
x = int(x)
y = float(y)

if x % 5 == 0 and x <= y - 0.50:
    print(y - (x+0.50))
else:
    print(y)


2. 
    x = int(input(x))
    y = float(input(y))
    
    if x % 5 == 0 and x <= y - 0.50:
        print(y - (x+0.50))
    else:
        print(y)

正如你所看到的,除了 x 和 y 的初始化之外,一切都是一样的——当第一批代码被接受时,第二批代码遇到了 NZEC 运行时错误。知道两者之间有什么区别吗?是因为 CodeChef 网站插入输入的方式吗?

标签: pythoninput

解决方案


推荐阅读