Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Nicolas Hampton
Nicolas Hampton
44,625 Points

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
6,141 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.