Jump to content

Mijnay

Member
  • Posts

    5
  • Joined

  • Last visited

Reputation Activity

  1. Agree
    Mijnay reacted to boggy77 in Python time   
    Hi @SamAnw, you have started a few threads, all related to the same thing. this questions has already been asked and people offered their help. If you need more help, continue on those threads, rather than starting new ones every 30 minutes.
  2. Agree
    Mijnay reacted to straight_stewie in What language should I choose   
    I would choose C# or Python.

    But, given the very loose requirements, you could use nearly any popular general purpose language.
  3. Agree
    Mijnay got a reaction from SamAnw in Outputs missing   
    This is the main issue. Your print statement only executes once. However you want the print statement to run for each line in the file, so a loop is a good choice.
     
    At the start of your program "a = file.read()" reads the entire file into the variable "a". One option is to use a for loop over the lines in the file:
     
    txt = "Prob06.in.txt" file = open(txt,"r") for line in file: state = line.split() pos = "W" neg = "B" ... LED1= int((n - LED2)/4) print(LED[LED1], LED[LED2]) Notice that from the line "state = line.split()" to print are all indented, putting them inside that for loop.
     
     
    Here is my complete rewrite of your program for your perusal (and because I want to look/feel clever). It is obviously different from your program, so don't turn it in as your own homework:
    STATES = {"BADGER": 0, "MUSHROOM": 1} LED = ("off", "red", "green", "blue") with open("in") as f: for ln, line in enumerate(f): try: bits = [STATES[i] for i in line.split()] led1, led2 = 2*bits[0] + bits[1], 2*bits[2] + bits[3] print(LED[led1], LED[led2]) except: print(f"Bad line: {ln}")  
×