![](/img/trans.png)
[英]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.