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 trialSabeen Azhar
440 Pointswhy does my if else statement not work?
why is
confirm = input("do you want to proced? Y/N ")
in a loop even if one these perameters are met?
if confirm == "y":
print("SOLD!")
tickets_remaining -= number_of_tickets
elif confirm == "n":
sys.exit("thanks anyways {}!".format(name))
thanks in advance!
import sys
TICKET_PRICE = 10
tickets_remaining = 100
print("there are {} tickets left".format(tickets_remaining))
name = input("what is your name? ")
number_of_tickets = int(input("how much tickets would you like, {}? ".format(name)))
amount_due = number_of_tickets * 10
print("that would be ${}, {}.".format(amount_due, name))
print("are you sure you want to go through with this? ")
confirm = input("do you want to proced? Y/N ")
while confirm.lower != ("y", "n"):
print("whoops! try again!")
confirm = input("do you want to proced? Y/N ")
if confirm == "y":
print("SOLD!")
tickets_remaining -= number_of_tickets
elif confirm == "n":
sys.exit("thanks anyways {}!".format(name))
```
2 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsHey Sabeen Azhar, there a a few problems with your while
loop conditional
-
confirm.lower
is a bound method. Without specifying the () parens to call the function, this is a reference to the executable itself. - comparing to a tuple
("y", "n")
will only match another tuple of the same values.
You can use the in
operator to see if something is "in" a container of values, such as a tuple:
while confirm.lower() not in ("y", "n"):
Post back if you need more help. Good luck!!
Sabeen Azhar
440 PointsThank you for the answer Chris Freeman, it worked perfectly!