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 trial
Manuel Canario
1,458 Pointsmasterticket.py Getting a weird string when I run My code after adding the function.
This is my code: TICKET_PRICE = int(10) SERVICE_FEE = int(2)
tickets_remaining = 100
def final_price(ticket_amount): final_price = int(ticket_amount) * int(TICKET_PRICE) + int(SERVICE_FEE)
while tickets_remaining >=1:
print("We only have {} tickets remaining, buy yours now.".format(tickets_remaining)) name = input("Hi, I see you are interested in buying tickets. What is your name? ") ticket_amount = input("Well hello {}, nice to meet you. How many tickets would you like to buy? ".format(name))
final_amount = str(final_price)
try: ticket_amount = int(ticket_amount) except ValueError as err: print("Oh no, can you type a valid quantity") else: print("Great, your total for {} tickets is $ {}.".format(ticket_amount, final_amount))
keep_buying = input("Are you sure you want to continue Y/N? ")
if keep_buying.lower() == "y": print("Sold to {}".format(name)) tickets_remaining = tickets_remaining - ticket_amount else: print("Remember to come back before we ran out.")
print("Sorry we are all out of tickets")
This is the weird string: (<function final_price at 0x7f67aafe7e18>)
treehouse:~/workspace$ python masterticket.py
We only have 100 tickets remaining, buy yours now.
Hi, I see you are interested in buying tickets. What is your name? Manuel
Well hello Manuel, nice to meet you. How many tickets would you like to buy? 10
Great, your total for 10 tickets is $ <function final_price at 0x7f67aafe7e18>.
Are you sure you want to continue Y/N?
1 Answer
KRIS NIKOLAISEN
54,974 PointsYou are missing the parameter for final_price here
final_amount = str(final_price)
should be
final_amount = str(final_price(ticket_amount))
Also your final_amount function should have a return statement:
def final_price(ticket_amount):
return int(ticket_amount) * int(TICKET_PRICE) + int(SERVICE_FEE)