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

less than (<) greater than (>) "Python" > "chocolate" ? "welcome" age < 13

Im a little confused on why "Python" > "chocolate" came out as True and not False and why age < 13 came out as "Welcome you can watch this PG-13 movie" wouldn't they choose between 1 and 13 so shouldn't it be you're not old enough?

3 Answers

Hi Renee, If you can add in your code, that would be helpful. You said:

I'm a little confused on why "Python" > "chocolate" came out as True and not False

That's impossible because the letter P's Unicode is U+0050 and c's is U+0063. You might have a typo or something. Since I can't explain stuff that well, this article explains string comparisons perfectly.

why age < 13 came out as "Welcome you can watch this PG-13 movie" wouldn't they choose between 1 and 13 so shouldn't it be you're not old enough?

I'm assuming this is your code:

age = int(input("Please type in your age \n>"))
if age < 13: # if age is less than 13
    print("Welcome, you can watch this PG-13 movie")
else:
    print("You must be above the age of 13")

You need to change the comparison condition to age >= 13

age = int(input("Please type in your age \n>"))
if age >= 13: # if age is greater than or equal to 13
    print("Welcome, you can watch this PG-13 movie")
else:
    print("You must be above the age of 13")

Thank you for responding. For the python question, it was on of the questions in the module and whenever i would hit False i kept getting the answer incorrect, i thought the same thing you wrote but the only way I could move on is by saying True.

hmm... Then maybe it's "python" > "chocolate". Can you link me the question?

Yes that's question. So i wrote false bc python is not greater bc alphabetically chocolate or "c" comes before "p".

Okay, you must know that there is a difference between "P" and "p". The latter's Unicode value is greater than the former's. Also, they're not compared based on their alphabetical order. They're compared based on their Unicode value. Read the article that I linked to in my initial answer.

example:

if "p" > "c":
    print(True) # prints True because the letter p's unicode value is greater
else:
    print(False)

if "P" > "c":
    print(True)
else:
    print(False) # prints False because the letter c's unicode value is greater

Sorry I completely forgot to thank you again for re-explaining this to me, thanks, I appreciate it.

No worries :)