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 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
210,425 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.

Tomasz Furmanczyk
seal-mask
.a{fill-rule:evenodd;}techdegree
Tomasz Furmanczyk
Web Development Techdegree Student 16,079 Points

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))