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
Shmuel Zilberman
1,409 Pointspython
ive fallowed along with the class but there is one thing i didn't really understand is the "def" function over here can some one please explain what it does and whats its doing over here thanks in advance
SERVICE_CHARGE = 2 TICKET_PRICE = 10
tickets_reamining = 100
this part...
def calculate_price(number_of_tickits): return number_of_tickets * TICKET_PRICE * SERVICE_CHARGE
while tickets_reamining >= 1:
print("there are {} tickets reamining.".format(tickets_reamining))
name = input("whats your name ? ")
tickits_you_want = input("how many tickets you want {} ".format(name))
try:
tickets_you_want = int(tickets_you_want)
if tickets_you_want > tickets_reamaning:
raise ValueError("there are on an x amount of tickets left try again man")
except ValueError as err:
print("oh no that doesnt make that much sence type something that makes sence..")
else:
ammount_due = calculate_price(num_tickets)
print("the total is {}".format(ammount_due))
keep_going_man = input("do you wanna continue ? y/n ")
if should_prossed.lower() == "y"
print("sold please come by again dear")
tickets_remaining -= num_tickets
else:
print("you suck")
1 Answer
Ivan Kazakov
Courses Plus Student 43,317 PointsThere's probably a typo in your function. It is most likely defined as follows:
def calculate_price(number_of_tickits):
return number_of_tickets * TICKET_PRICE + SERVICE_CHARGE
That is, SERVICE_CHARGE is added rather than multiplied by. It adds a fixed fee of 2 dollars to total amount.
Øyvind Andreassen
16,840 PointsØyvind Andreassen
16,840 PointsLooks like you have some typos in your variable names. On line 4 you declare
tickits_you_want, but in the try you checktickets_you_want. Alsotickets_remainingis misspelledtickets_remaining.