Jump to content

SamAnw

Member
  • Posts

    11
  • Joined

  • Last visited

Awards

This user doesn't have any awards

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

SamAnw's Achievements

  1. SamAnw

    Python time

    Hello everyone, I need to create a program that converts an input like this one: 1m and 45s 10m,10s 32s, and 12h 76h 1s Into an output like this one: 00:01:45 00:10:10 12:00:32 76:00:00 00:00:01 Does anyone have an idea of how to do this? Thanks in advance
  2. Hello, Thanks so much for trying to help, I really appreciate it. I tried adding for i in list in the program, but I don't think I'm addind it correctly or maybe it just isn't working, but there's still an output error...
  3. I took out the lines where I'm trying to tell the computer what the variables are and so this is my code: txt = "Prob05.in.txt" msg = open(txt, "r") msg = msg.read() h = msg.split("\n") first = True unSentence = 1 countSentence = 1 while(countSentence <= h[0]): while (unSentence <= g[0]): Sentence = '\n' seq = input (Sentence.format (unSentence)) print((g[i] - min(lst))/(max(lst) - min(lst))*255) unSentence += 1 countSentence += 1 But now the type error is: Traceback (most recent call last): File "C:/Users/admin/Desktop/Collège Sainte Marcelline Prog (8)/Problème 05.py", line 8, in <module> while(countSentence <= h[0]): TypeError: '<=' not supported between instances of 'int' and 'str' That's why I was trying to add the variable=int... Thanks so much Sam
  4. I tried to add the h=int line after the msg.split("\n"), but this type error pops up: Traceback (most recent call last): File "C:/Users/admin/Desktop/Collège Sainte Marcelline Prog (8)/Problème 05.py", line 10, in <module> while(countSentence <= h[0]): TypeError: 'type' object is not subscriptable As for the g, I'm trying to tell the computer it's a float variable, but I'm not sure it's the right thing to do... Thankyou so much for helping!
  5. I've only recently started programming with python, so I have no idea what I could do to fix this, but as for the list, it's my input values... I'm really confused Thankyou
  6. Hello! I've been working on this program and I don't know why, but there seems to be a problem with it... txt = "Prob05.in.txt" msg = open(txt, "r") msg = msg.read() h = msg.split("\n") h=int g = float first = True unSentence = 1 countSentence = 1 while(countSentence <= h[0]): while (unSentence <= g[0]): Sentence = '\n' seq = input (Sentence.format (unSentence)) print((g[i] - min(lst))/(max(lst) - min(lst))*255) unSentence += 1 countSentence += 1 My file input is: 2 5 0.0 25.0 50.0 75.0 100.0 6 12.3 -67.1 122.8 428.4 -15.9 221.0 But when I try to run the program, there is an error: Traceback (most recent call last): File "C:/Users/admin/Desktop/Collège Sainte Marcelline Prog (8)/Problème 05.py", line 10, in <module> while(countSentence <= h[0]): TypeError: 'type' object is not subscriptable Anyone has got an idea?
  7. SamAnw

    Python time

    Hello I have to write a python program that changes an input file like the following: 1 hour 20 minutes 30 minutes and 2 hours into an output file like the following: 01:20:00 02:30:00 I have no idea what to do Thankyou!
  8. Hello everyone! I've been working on this program: txt = "Prob03.in.txt" msg = open(txt, "r") msg = msg.read() n=int countCase=1 for prob in msg: prob =prob.split() i =0 while i<2: prob[i] = int(prob[i]) i=+1 if prob[0] != prob[1]: print("false") elif prob[0] == prob[1]: print("true") My txt file looks like this: 2 true false true true I don't understand why it's not working Thankyou!
  9. I have no idea how to print it more than once...I've just started learning python so I'm missing some base ya know It would be great if you could help! Thankyou!!
  10. 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!
  11. Hello, I've been working on a python code to trace the movement of the bishop in a chess game. I'm working with odd and even coordinates to know if the bishop can move or not, and it can move more than once to reach the final coordinate. My code does not work when it comes to the 'if' statement and it states "not all arguments converted during string formatting"...I've tried adding 'int' and stuff, but it's just not working..Help!! Code: 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")
×