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

Anthony Burt
seal-mask
.a{fill-rule:evenodd;}techdegree
Anthony Burt
Python Development Techdegree Student 644 Points

Less than or equal

Hello, Why in the following code would you right -= rather than >= I am trying to understand the difference. If I put >- then the remaining tickets counter does not lower.

 #If they want to proceed 
  if should_proceed.lower() =="y":
    #Print out to the screen "SOLD!" to confirm purchase
      print("SOLD!")
      #and then reduce the tickets remaining by the number of tickets purchased. 
      tickets_remaining -= num_tickets

[MOD: added ```python formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,515 Points

Hey Anthony Burt, there certainly are a lot of operators in python! The += is an in place operator where:

a += b
# same as
a = a + b

that is, add b to a and put the result back in a. So in the code above, num_tickets is subtracted from tickets_remaining and the result is placed back into tickets_remaining.

The >= is a value comparison operator where the expression:

a >= b

returns a True value if a is greater or equal to b.

There is no >- operator. (perhaps a typo?)

Anthony Burt
seal-mask
.a{fill-rule:evenodd;}techdegree
Anthony Burt
Python Development Techdegree Student 644 Points

Hello Chris. Thank you so much for the detailed answer! That makes a lot more sense. Yes, this >- was a typo. I meant type >= I see now why that was not working.