什么是python中的输出文件

2024-05-17 00:06:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我开始研究谷歌代码堵塞的问题。不过,我的意见似乎有问题。每当我提交时,我都被告知“你的输出应该以‘Case#1:’”开头。我的输出一个print语句以“Case#%s:%s”%(y+1,p)开头,表示Case#1:ext。。。当我运行代码时。在

我看了看,上面写着“你的输出应该以‘Case#1:’:如果你收到这个消息,确保你没有上传源文件而不是输出文件,并且你正确地输出了案例号。输出文件的第一行应始终以“Case#1:”开头,后跟空格或行尾

那么什么是输出文件,我如何将它合并到我的代码中呢?在

额外信息:这是我的代码,我将其保存为GoogleCode1.py并提交该文件。我在空闲时写的。在

import string
firstimput = raw_input ("cases ")
for y in range(int(first)):
    nextimput = raw_input ("imput ")
    firstlist = string.split(nextimput)
    firstlist.reverse()
    p = ""
    for x in range(len(firstlist)):
        p = p +firstlist[x] + " "
    p = p [:-1]
    print "Case #%s: %s"%(y + 1, p)

Tags: 文件代码inforinputstringrawrange
3条回答

撇开I/O重定向不谈,另一种方法是读写各种文件。查找file handling in python

input_file = open('/path/to/input_file')
output_file = open('/path/to/output_file', 'w')
for line in input_file:
    answer = myFunction(line)
    output_file.write("Case #x: "+str(answer))
input_file.close()
output_file.close()

干杯

确保你提交的文件包含你的代码输出,而不是在一轮练习中提交代码本身。在

在shell中运行脚本,并重定向输出。在

python GoogleCode1.py > GoogleCode1.out

相关问题 更多 >