Feb-12-2020, 04:50 AM
Hello,
I've been working on a python program that reads a file instead of inputs. However, there seems to be a problem in my program and it won't read after the first line of the file, so I'm only getting part of the outputs.
Here's the file:
Prob.06.in
WORKING WORKING WORKING WORKING
WORKING BROKEN BROKEN WORKING
BROKEN BROKEN BROKEN BROKEN
And here's the code:
off off
red green
blue blue
But the output I'm getting is:
off off
Thankyou in advance!
I've been working on a python program that reads a file instead of inputs. However, there seems to be a problem in my program and it won't read after the first line of the file, so I'm only getting part of the outputs.
Here's the file:
Prob.06.in
WORKING WORKING WORKING WORKING
WORKING BROKEN BROKEN WORKING
BROKEN BROKEN BROKEN BROKEN
And here's the code:
from math import * txt = "Prob06.in.txt" file = open(txt,"r") a=file.read() state = a.split() pos = "W" neg = "B" i=0 n=0 while i < 4: if state[i].startswith(neg): n += 8/(2**i) elif not state[i].startswith(pos): print("invalid entry 1") i+=1 LED = ('off','red','green','blue') LED2= int(n % 4) LED1= int((n - LED2)/4) print(LED[LED1], LED[LED2])The output of this program should be:
off off
red green
blue blue
But the output I'm getting is:
off off
Thankyou in advance!