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

Regina Ackah
Regina Ackah
2,632 Points

my code does NOT subtract

please help me solve the issue with my code. tickets_remaining does not subtract after I can't seem to find the problem at all.

while tickets_remaining >=1 : print("We have {} tickets remaining".format(tickets_remaining)) name = input("What is your name? ") num_tickets = int((input("How many tickets do you need {} ".format(name)))) user_price = num_tickets * TICKET_PRICE print("Total due is ${}".format(user_price)) proceed = input("do you want to continue? Y/N ") if proceed.lower() == "Y": print("sold") tickets_remaining = tickets_remaining - num_tickets else: print("Thank you {}".format(name)) print("Sorry the tickets are sold out ")

AJ Tran
seal-mask
.a{fill-rule:evenodd;}techdegree
AJ Tran
Treehouse Teacher

You can wrap your code in triple backticks to format it neatly. When you open the text editor to make a post or comment, there is a link that says

Reference this Markdown Cheatsheet for syntax examples for formatting your post.

And there is an example in there.

while tickets_remaining >=1 : 
    print("We have {} tickets remaining".format(tickets_remaining)) 

    name = input("What is your name? ") 
    num_tickets = int((input("How many tickets do you need {} ".format(name)))) 
    user_price = num_tickets * TICKET_PRICE 

    print("Total due is ${}".format(user_price)) 
    proceed = input("do you want to continue? Y/N ")

    if proceed.lower() == "Y": 
        print("sold") tickets_remaining = tickets_remaining - num_tickets 
    else: 
        print("Thank you {}".format(name)) 
        print("Sorry the tickets are sold out ")

1 Answer

AJ Tran
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
AJ Tran
Treehouse Teacher

Hi Regina Ackah! I found a little bug in your conditional :)

if proceed.lower() == "Y":
    tickets_remaining = tickets_remaining - num_tickets

proceed.lower() is never going to be equal to "Y"! Because the code will always compare a lowercase letter to a capital letter. It will always return False, so your next line of subtracting code will never run.

So the easiest fix would be to change your conditional to compare against a lowercase "y".

It happens to everyone! One character will ruin the whole program with a bug and sometimes you just need another person to read the code :)

Regina Ackah
Regina Ackah
2,632 Points

oooh Thanks soo much, i have been on this for hours.