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

Python Python Basics All Together Now Cleaner Code Through Refactoring

When I get to total my code spits out "your total is None." I'm not sure how I am getting this. Iv been following along.

TICKET_PRICE = 10

tickets_remaining = 100

def calculate_price(num_tickets): result = num_tickets * TICKET_PRICE

while tickets_remaining > 0: print("There are {} tickets remaining.".format(tickets_remaining)) name = input("What is your name?\n") number_of_tickets = (input("How many tickets would you like {}?\n".format(name))) try: number_of_tickets = int(number_of_tickets) if number_of_tickets > tickets_remaining: raise ValueError(" There are only {} tickets remaining.".format(tickets_remaining)) # Raise value error if request is for more tickets than are available except ValueError as err: #include error text in the output print("Make sure you enter a valid number and try again.{}".format(err)) else: total = calculate_price(number_of_tickets) print("{}, your total is {}.".format(name, total)) proceed = input("Would you like to proceed {}? Y or N\n".format(name)) if proceed.capitalize() == "Y": # TODO: Gather CC info print("Sold!") tickets_remaining = tickets_remaining - number_of_tickets print(tickets_remaining, "Ticket remaining.") elif tickets_remaining == 0: break else: print("Thank you anyways, {}.".format(name))

print("Sold Out!")

1 Answer

Your calculate_price function isn't returning anything.

Good catch Joseph.

The calculate_price function is assigning the total cost of num_tickets * TICKET_PRICE to the variable 'result', however the function needs to return the result to make it usable in other parts of the programme.

There should be another line in the function that says return result

Alternatively you don't need to assign the result variable at all and can just return the outcome of the calculation within the function like this: return num_tickets * TICKET_PRICE