Created
October 3, 2011 02:13
-
-
Save codeeval/1258294 to your computer and use it in GitHub Desktop.
Sample code to read in test cases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# On CodeEval, test cases are read in from a file which is the first argument to your program | |
# Open the file and read in line by line. Each line represents a different test case | |
# (unless given different instructions in the challenge description) | |
import sys | |
test_cases = open(sys.argv[1], 'r') | |
for test in test_cases: | |
# ignore test if it is an empty line | |
# 'test' represents the test case, do something with it | |
# ... | |
# ... | |
test_cases.close() |
What do i write as input and output filenames?
Here's some starter code for Fortran. #MakeFortranGreatAgain
program main
implicit none
character(32) :: tests
character(10) :: test
integer :: stat
!Get file name
call get_command_argument(1, arg)
!Open file
open (11,file=trim(arg),action='read')
do
!read in test
read (11,'(a)',iostat=stat) test
if (stat /= 0) exit
if (str /= '') then
.........
! Code goes here
.........
end if
end do
close (11)
end program main
Please show me an example for python3, if you need to pass a parameter to the function, how do I issue the code?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I must be getting severely confused about how to run a program with input containing multiple lines. Can someone walk me through how to submit an answer for the challenge linked below? Basically sum of the lines. The actual function that would add up all of the numbers is easy enough, but I do not understand how to make my input be the different numbers from a file with multiple lines.
Working in Javascript.
https://www.codeeval.com/open_challenges/24/