Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Types and Branching Booleans

Confused about dating site scenario

In the dating site scenario Craig states that Heidi wants to meet someone with kids but does not want someone who smokes.

Therefore if someone is "not is_smoker" then wouldn't that suit her needs? However the code returns a False.

If you look at it like;

has_kids and is_smoker

Then the code would return True

However Heidi does not want to meet a smoker so it wouldn't be a match for her, and True wouldn't really be accurate.

Wouldn't this be more suitable;

non_smoker = True
has_kids = True
non_smoker and has_kids
True

not non_smoker and has_kids
False

Am I missing something here?

Joy San Nicolas
Joy San Nicolas
459 Points

I'm with you on this one. I figured Heidi would want Joe if he's: has_kids and not is_smoker If that returns a False, (which it would, since non_smoker = True), then we're to assume she would "swipe left" for Joe even when they're actually a match?

I'm still not sure what the fix would be to finding a match for Heidi though. Maybe....:

is_smoker = False

That way, has_kids and not is_smoker will return True for Heidi

2 Answers

I think you're understanding everything pretty well, actually, but you're caught on the variable names, which is completely understandable. Naming things is one of the hardest parts of programming, and your confusion is a perfect example as to why.

If the hypothetical site Craig is referencing was ONLY for matching people with Heidi, then it might make sense to name everything around what Heidi prefers to keep things simple. Heidi prefers non_smokers, so on heididates.com it would make sense to name it non_smoker. That way when heidi fills out her preferences, she'd say non_smokers and has_kids, and the logic on her end would be really simple.

But for most every programming problem, solutions aren't for just one person or example. When making a site like exampledate.com that matches millions of different people on millions of different dates, it makes a lot more sense to name all the variables as Truthy by default. That way we don't have to think too much about "should this boolean variable be true or false by default, and what does that mean?". So, in the wild, you're much more likely to see "is_something" or "has_something" than "non_something" or "missing_something". In the grand scheme of things, it's easier to reason about.

So, in Craig's example, Joe would fill in True for is_smoker and True for has_kids in his dating profile, and Heidi would fill out not is_smoker and has_kids as her preferences. Naming things is hard, but generally it's best to name boolean values from the perspective of Truthy. I hope that helps, good question!

Also, one thing that might help is that the instructors description of it might just be confusing.

Because in this situation, aren't they saying that Joe is_smoker and Joe has_kids therefore true and true = true. Heidi however is looking for not is_smoker and has_kids therefore false and true = false. So true and false do not match. Right?

I completely understand the naming of variables and how that's tough. I just feel like the video was missing a part. So confusing because it's all true false false true true true false true true. Break it down for us, teach!

fahad lashari
fahad lashari
7,693 Points

the 'not is_smoker' basically means check and tell me if is_smoker = True, if is_smoker = True then return false.

In the real world the person filling out the application will answer true or false to whether they are a smoker and their answer will be assigned to the variable is_smoker.

So Heidi wants someone with kids and a non smoker so her application has:

has_kids = True is_smoker = False

and the other person has:

has_kids = True is_smoker = True

so when we do has_kids and not is_smoker, Heidi's profile requirements check the other person's profile and it will return True for has_kids and True for is_smoker but by saying 'not is_smoker' we want someone who's profile doesn't have is_smoker = true hence why it returns false. Hope that helps.

I know it can be confusing but after a few read time you read it, you'll start to grasp it. It took me a few read throughs. I I do agree that it should have been explained abit more in the video.

Tricia Cruz
Tricia Cruz
915 Points

Hello, fahad from the past. I'm just jumping in 4 years later because I'm a bit confused too, but I think I'm getting it... Can someone confirm though please for my peace of mind?

So in the scenario in the video, the "has_kids = True is_smoker = True" that the instructor showed, that's a sample profile? So it ISN'T us (badly put) saying in the code something like "has_kids means True" (like assigning a variable)? I think that was where my confusion began, because I thought he was assigning it like a variable 😅