0

I'm starting to work on problems for google's Code Jam. However I there seams to be a problem with my submission. Whenever I submit I am told "Your output should start with 'Case #1: '". My output a print statement starts with ""Case #%s: %s"%(y + 1, p)" which says Case #1: ext... when I run my code.

I looked into it and it said "Your output should start with 'Case #1: ': If you get this message, make sure you did not upload the source file in place of the output file, and that you're outputting case numbers properly. The first line of the output file should always start with "Case #1:", followed by a space or the end of the line."

So what is an output file and how would I incorporate it into my code?

Extra info: This is my code I'm saving it as GoogleCode1.py and submitting that file. I wrote it in the IDLE.

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)
7
  • 1
    First, you should almost certainly not use raw_input in Code Jam, since you're given the input as a file and it doesn't make sense to prompt for it. Second, it's perfectly fine to just use print statements to generate the output, since you can just use your shell to capture it to a file. Commented Mar 5, 2012 at 3:38
  • @Wooble: raw_input() is fine here. Redirection. Commented Mar 5, 2012 at 3:40
  • @IgnacioVazquez-Abrams: testing this myself, the prompts end up in the output file. Commented Mar 5, 2012 at 3:43
  • 1
    It's even easier to avoid in the first place, IMO. Commented Mar 5, 2012 at 3:44
  • 1
    Actually, I believe that many online / autojudged competition mark it as an incorrect output. Btw, input is spelled with an "n" instead of "imput" Commented Mar 5, 2012 at 5:02

3 Answers 3

2

Run the script in a shell, and redirect the output.

python GoogleCode1.py > GoogleCode1.out
Sign up to request clarification or add additional context in comments.

1 Comment

This is easier for development too. You can let it write to the console while developing it, and then "save" it to a file when you're sure it works.
1

I/O redirection aside, the other way to do this would be to read from and write to various files. Lookup 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()

Cheers

Comments

1

Make sure you're submitting a file containing what your code outputs -- don't submit the code itself during a practice round.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.