[英]Python subprocess: Print to stdin, read stdout until newline, repeat
[英]Read and print “STDIN and STDOUT”
我当时在HackerRank上进行了示例测试,尽管我知道如何编写问题解决方案的代码,但我不了解stdin和stdout系统。 我的代码未获取参数,并且在stdout上未打印任何内容。
给定一个整数L和R(每个在stdin上的一行)在stdout上打印它们之间的奇数(在一个数组上)。
def oddNumbers (l, r): #this was already here
l=int(input())
r=int(input())
list1=[]
for i in range (l+1, r):
if i%2 == 1:
list1.append(i)
print(list1)
return
if__name'__main__': #this was already here
# ...
您不应该自己阅读输入或打印结果。 指示说
编辑器中已锁定的存根代码从stdin读取以下输入, 并将其传递给函数
和
该函数必须返回一个整数数组...
因此,摆脱int(input())
行,并更改print(list1)
来return list1
。
我看不到您在顶部引用的说明,它们不在底部的站点图像中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.