Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Mijnay

Member
  • Content Count

    4
  • Joined

  • Last visited

Awards


This user doesn't have any awards

About Mijnay

  • Title
    Newbie
  1. This is only true if one is unwilling to dedicate all the resources necessary to truly solve the problem. For all decideable problems, there exists a no compromise solution. Sometimes it just requires a lot to get there. Compromise can always be replaced by work. @straight_stewie I believe in this example the original constraints made the problem impossible, so I am not sure why you bring up the idea of a no compromise solution. If you are able to change an item's price in increments of 0.01 and are not allowed to change item counts, the problem is impossible in general. Proof by example: count x price 1000 x 0.01 = 10.00 ------------------- total = 10.00 Payment = 5.00 To account for the payment the item's price would have to be lowered. The price can be lowered to 0.00, however that price is to low to account for the payment. Since the price 0.01 is too high and 0.00 is too low and there is no possible price in between, the price cannot be adjusted to account for the payment.
  2. Mijnay

    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}")
  3. Don't forget to use the forum's code tag: a =1 while a==1: Numcas = int(input("How many cases do you have?: ")) countcas = 1 state = a = input('Enter the amount of columns and rows in your game: ') h = a.split(",") coltotal = int(h[0]) rowtotal = int(h[1]) if (2<=coltotal<=1000 and 2<=rowtotal<=1000): while (countcas <= Numcas): question2 = 'Enter the starting position in the case #{}: ' positionst = input(question2.format(countcas)) position = positionst.split(",") colstart = int(position[0]) rowstart = int(position[1]) question4 = 'Enter the finishing position number in the case #{} ' positionend= input(question4.format(countcas)) positionen = positionend.split(",") colend = int(positionen[0]) rowend = int(positionen[1]) countcas+=1 seqcount = 1 if positionst[0] % 2 == 0 and positionst[1] % 2 == 0 and positionend[0] % 2 ==0 and positionend[1] % 2 ==0: print ("TRUE") if positionst[0] % 2 !=0 and positionst[1] % 2 !=0 and positionend[0] % 2 !=0 and positionend[1] % 2 !=0: print ("TRUE") if positionst[0] % 2 !=0 and positionst[1] % 2 ==0 and positionend[0] % 2 !=0 and positionend[1] % 2 ==0: print ("TRUE") if positionst[0] % 2 ==0 and positionst[1] % 2 !=0 and positionend[0] % 2 ==0 and positionend[1] % 2 !=0: print ("TRUE") else: print ("FALSE") The issue is that positionst and positionend are strings. This causes the % operator to be interpreted as string interpolation. You probably want to replace positionst[0] with colstart, positionst[1] with rowstart, etc... Those are your integers which will have % do the modulus operation like I think you are expecting. Feel free to ask more questions.
  4. file = open("Links.txt", "r") for i in range(2): line = file.readline() print(line) matches = re.match('https://domain.com/works/[0-9]+', line) if not matches: print("FAILURE to match regex.") else: removedEnd = matches.group(0) print(removedEnd) The above should work. As IAmAndre mentioned the pattern needed to be changed as well as the arguments to search/match. I used match instead of search, but either should work fine for your use case. Feel free to ask more questions as you try to understand and modify the code.
×