USACO Code Submission Problem – Output File Missing

Question:

I’ve started practicing for the USACO contest tomorrow, I’m relativly new so I’m not too familiar with their input/output methods. Here’s the code I submitted to the website

n = int(input())
a = input()
b = input()

swap_number = 0
a_list = []
b_list = []

for i in range(n):
  if a[i] != b[i]:
    a_list.append(a[i])
    b_list.append(b[i])

one_value = 0
two_value = 0

for x in range(len(a_list)):
  if a_list[x] == "H":
    one_value += 1
  else:
    two_value += 1


list = [one_value,two_value]
list.sort()

swap_number = list[0] + (list[1]-list[0])

print(swap_number)

after loading for a couple minutes, it displayed:
Your output file breedflip.out:
[File missing!]

I rewrote, retested every problem using this simple code, but still receive the same error
Would this code not create an output file and how can I put the outputted answer in the file

Asked By: DDoubleDDarren

||

Answers:

Try to add these two lines in your beginning of codes: (just test and it passed with my revised code) Your code might not be working!


import sys

sys.stdin = open('breedflip.in', 'r')
sys.stdout = open('breedflip.out', 'w')

n = int(input())
a = list(input())   # list
b = list(input())
...........
Answered By: Daniel Hao
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.