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 All Together Now Branch and Loop

!= vs ==

I though != meant "is not". In the below logic, I wrote it down in a way like saying "if the user refuses to buy the tickets, then say "Thank you". But regardless if the answer is Y or N, it stays in the "if" loop, how come?

proceed = input("Would you like to proceed, {}? Y/N " .format(name)) if proceed.lower() != "n": print("SOLD!") tickets_remaining = tickets_remaining - num_tickets
else: #say Thank them by name. print("Thank you, {}." .format(name))

!= is bang or not equal to, == is checking comparrison and = is assigning

2 Answers

Steven Parker
Steven Parker
231,269 Points

The loop would be defined with a "for" or "while", neither of which are shown here.

Also, what's inside the loop is determined by indentation. For your indentation to show up you have to post your code using Markdown formatting.

This all depends on how you would like to structure the conditional statement. However, the more efficient design would be:

proceed = input("Would you like to proceed, {}? Y/N " .format(name))

if proceed.lower() == "y": print("SOLD!") tickets_remaining = tickets_remaining - int(num_tickets)

else:
print("Thank you, {}." .format(name))