Using loop counters to input files (Python3)
Go to solution
Solved by lewdicrous,
These worked:
From what @mariushm and @M.Yurizaki wrote:
x = 1 while x <= 5: y = 1 while y <= 2: infile = open("Team%d_Round%d.txt" %(x,y), "r") score = infile.readline() while score != "": print (score, end="") score = infile.readline() print () y += 1 x += 1
And this is what @vorticalbox wrote:
for x in range(1,6): for y in range(1,3): with open("Team%d_Round%d.txt" %(x,y), "r") as f: for line in f.readlines(): print(line)
Thank you!
Note: I changed them a bit so that they print the results from the first round first and then the second round (in my program), other than that it's the same.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now