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 trialAnthony Burt
Python Development Techdegree Student 644 PointsLess 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
Treehouse Moderator 68,441 PointsHey 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
Python Development Techdegree Student 644 PointsAnthony Burt
Python Development Techdegree Student 644 PointsHello 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.