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

Nick Evershed
Nick Evershed
6,409 Points

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

2 Answers

Steven Parker
Steven Parker
204,010 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
Front End Web Development Techdegree Student 15,433 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))