Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If statement not working
#4
I think you want to break out of the loop when the condition is True. But in fact you continue to loop till the end of the file. So at that moment the value of datafile1 is expenses-18 and on line 26 you override the value of datafile that was assigned when the condition was True with the current one (i.e. the last entry in the file).
That said your code has many redundant parts and overall algorythm is far from efficient/best/pythonic one
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
If statement not working - by oldcity - Oct-09-2018, 11:57 PM
RE: If statement not working - by stullis - Oct-10-2018, 12:39 AM
RE: If statement not working - by micseydel - Oct-10-2018, 12:41 AM
RE: If statement not working - by buran - Oct-10-2018, 06:48 AM
< SOLVED >RE: If statement not working - by oldcity - Oct-14-2018, 10:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question If, elif, and else statement not working PickleScripts 3 983 Mar-30-2023, 02:53 PM
Last Post: PickleScripts
  If statement not working correctly? MrKnd94 2 888 Nov-16-2022, 02:49 AM
Last Post: deanhystad
  If Statement not working...Why? Milfredo 2 2,274 Oct-17-2020, 03:23 AM
Last Post: Milfredo
  Invoking function in if else statement, not working! ibaad1406 13 5,842 May-30-2019, 09:05 PM
Last Post: ibaad1406
  if statement not working trent101010 8 5,136 Mar-14-2018, 03:19 PM
Last Post: wavic
  why is this try.....except statement not working? HenryJ 3 8,850 Feb-06-2018, 06:15 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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