简体   繁体   English

读取并打印“ STDIN和STDOUT”

[英]Read and print “STDIN and STDOUT”

在此处输入图片说明

I was doing a sample test on HackerRank, and although I knew how to code a solution to the problem, I didn't understand the stdin and stdout system. 我当时在HackerRank上进行了示例测试,尽管我知道如何编写问题解决方案的代码,但我不了解stdin和stdout系统。 My code didn't get the parameters and print nothing on stdout. 我的代码未获取参数,并且在stdout上未打印任何内容。

Given a integer L and R (each one from a line on stdin) print on stdout the odd numbers(on an array) between them. 给定一个整数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
    # ...

在此处输入图片说明

You're not supposed to read the input or print the results yourself. 您不应该自己阅读输入或打印结果。 The instructions say 指示说

Locked stub code in the editor reads the following input from stdin and passes it to the function 编辑器中已锁定的存根代码从stdin读取以下输入, 并将其传递给函数

and

The function must return an array of integers... 该函数必须返回一个整数数组...

So get rid of the int(input()) lines, and change print(list1) to return list1 . 因此,摆脱int(input())行,并更改print(list1)return list1

I don't see where you got the instructions you quoted at the top, they're not in the image of the site at the bottom. 我看不到您在顶部引用的说明,它们不在底部的站点图像中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM