Python Forum
if condition not behaving as expected
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if condition not behaving as expected
#3
I tried all that type of possible solutions without any luck.

It seems that when the logic is printing the lines 'section... --> False' (or True), each iteration of 'a' is treated independently according to the value of 'a'. However, as soon as I start putting a print instruction (or any other instruction for that matter) into the 'if condition', it seems that all 'PointFound' boolean values for all 7 sections are regarded as a list. In that case, since one of the seven booleans is True, all 7 lines get evalutaed as True.

Notice also that when using the 'if condition', the additional print instruction is already printed out for sections 1 and 2 PRIOR (!) to arriving at section 3, which is the first (and only) section that returns a value True for 'PointFound'

In other words : although looping through 'a' from 1 to 7, the 7 results are not returned as individual values but rather as a list that evaluates entirely to TRUE because one single value is True.

The strange part is why 'True' is only printed one time (for section 3) by the original print instruction while the additional print line is printed 7 times for each section.
Reply


Messages In This Thread
if condition not behaving as expected - by EricBHK - May-16-2020, 10:44 AM
RE: if condition not behaving as expected - by EricBHK - May-16-2020, 12:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ConfigParser(dict_type=) not behaving as expected malonn 5 3,373 Sep-08-2022, 08:42 AM
Last Post: malonn
  Two loops behaving differently DavidTheGrockle 5 2,592 Dec-27-2020, 03:56 AM
Last Post: deanhystad
  else condition not called when if condition is false Sandz1286 10 6,024 Jun-05-2020, 05:01 PM
Last Post: ebolisa
  [HELP] Nested conditional? double condition followed by another condition. penahuse 25 8,285 Jun-01-2020, 06:00 PM
Last Post: penahuse
  Requests not behaving... PythonLamer 1 4,851 Dec-01-2017, 06:45 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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