Python Forum
If Statement not working...Why?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If Statement not working...Why?
#1
Here is a snippet of code and what it produces. I don't understand what is going on.

def complete_form():
	
	horses_names = []
	for i, var in enumerate(scratched):    
		scratched_list.append(var.get())   	
		
	
	for a in range(len(scratched_list)):
		if scratched_list[a] == 'True':
			print(horses_name[a])
		else:
			print(scratched_list[a])
Here is what it prints out. As you can see there is one condition that is True, but the code doesn't seem to recognize it. I don't know why. Where scratched_list[a] == 'True' horses name should appear, but I get 'True' instead.

$ python processing.py
False
False
True
False
False
False
Reply
#2
I also don't understand what is going on as I have no idea what scratched or scratched_list are. However, I noticed that on row #9 you check equality with string 'True' and not boolean value True. You may or may not wanted to have such comparison.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
perfringo,

Thanks so much. That was the problem. String versus Boolean.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question If, elif, and else statement not working PickleScripts 3 841 Mar-30-2023, 02:53 PM
Last Post: PickleScripts
  If statement not working correctly? MrKnd94 2 799 Nov-16-2022, 02:49 AM
Last Post: deanhystad
  Invoking function in if else statement, not working! ibaad1406 13 5,482 May-30-2019, 09:05 PM
Last Post: ibaad1406
  If statement not working oldcity 4 3,051 Oct-14-2018, 10:45 AM
Last Post: oldcity
  if statement not working trent101010 8 4,873 Mar-14-2018, 03:19 PM
Last Post: wavic
  why is this try.....except statement not working? HenryJ 3 8,714 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