Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if else condition issue
#4
Hi @gontajones, I tried your solution:
with open(file1.txt, "r") as f1:
               contents = f1.readlines()
               with open(output1.txt, "w+") as f2:
                       for line in contents:
                               if "wire" in line:
                                       if "input" in line:
                                               f2.write(line)
                                       elif "output" in line:
                                               f2.write(line)
                                       elif "result" in line:
                                               f2.write(line)
                                else:
                                       if "input" in line:
                                               f2.write(line)
                                       elif "output" in line:
                                               f2.write(line)
                                       elif "result" in line:
                                               #remove "result" word only
                                               f2.write(line)
However, its nt going thru the if "wire" in line, it goes straight to else statement. as it goes through else statement, it will print the result line without "result" word. Why it did not go through the if condition as it is true right?
Reply


Messages In This Thread
if else condition issue - by mmaz67 - Jul-17-2018, 08:51 AM
RE: if else condition issue - by gontajones - Jul-17-2018, 10:05 AM
RE: if else condition issue - by buran - Jul-17-2018, 10:52 AM
RE: if else condition issue - by mmaz67 - Jul-18-2018, 05:38 AM
RE: if else condition issue - by gontajones - Jul-18-2018, 09:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Issue with program not passing to other elif condition Abdirahman 6 2,285 Nov-21-2021, 07:04 AM
Last Post: Abdirahman
  else condition not called when if condition is false Sandz1286 10 6,174 Jun-05-2020, 05:01 PM
Last Post: ebolisa
  [HELP] Nested conditional? double condition followed by another condition. penahuse 25 8,592 Jun-01-2020, 06:00 PM
Last Post: penahuse

Forum Jump:

User Panel Messages

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