Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Outputs missing
#1
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:
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!
Reply


Messages In This Thread
Outputs missing - by SamAnw - Feb-12-2020, 04:50 AM
RE: Outputs missing - by michael1789 - Feb-12-2020, 06:21 AM
RE: Outputs missing - by SamAnw - Feb-12-2020, 03:47 PM
RE: Outputs missing - by Larz60+ - Feb-12-2020, 09:29 AM
RE: Outputs missing - by adetheheat - Feb-12-2020, 04:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Combining outputs into a dataframe rybina 0 152 Mar-15-2021, 02:43 PM
Last Post: rybina
  ONE input => THREE outputs Tricia279 6 360 Jan-14-2021, 08:52 AM
Last Post: perfringo
  Multi set string inputs/outputs kwmcgreal 2 419 Sep-26-2020, 10:44 PM
Last Post: kwmcgreal
  How to use subprocess to get multiple data outputs in desired folder? 3SG14 1 496 Sep-19-2020, 05:46 PM
Last Post: bowlofred
  Interpreter and running a .py file give different outputs PythonNPC 5 925 Jul-21-2019, 01:07 PM
Last Post: PythonNPC
  Save outputs to Desktop cisicomania 1 1,133 Aug-31-2018, 10:08 AM
Last Post: Gribouillis
  Help Editing/Problem with outputs stanthaman42 7 1,818 Jul-11-2018, 05:30 PM
Last Post: ichabod801
  how do i rewrite this code to give me 10 outputs BlackPimpernel 2 1,190 Mar-29-2018, 11:29 AM
Last Post: BlackPimpernel
  Different outputs in Python2 and Python3 MikeHill 3 2,205 Jun-07-2017, 08:58 PM
Last Post: Ofnuts
  Program that outputs HQ addresses of companies from Google + Local pages frenchgirl1309 2 2,478 Nov-14-2016, 10:11 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020