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 trialStephen Cole
Courses Plus Student 15,809 PointsMy way of dealing with grammar/plurals.
When I refactored the price calculation, I decided that I wanted to have the English match the amounts. That is, 1 ticket would cost $10 and 2 tickets would cost $20. This was my approach. I thought it to be both DRY and novel.
def calc_price(ticket_request):
total_cost = ticket_request * TICKET_PRICE
if num_tickets == 1:
plural = ''
else:
plural = 's'
print('{} ticket{} costs {} dollars'.format(num_tickets, plural, total_cost))
print('There is a service charge of ${} per transaction.'.format(SERVICE_CHARGE))
return total_cost + SERVICE_CHARGE
I'm not sure that I care about dollar vs dollars as I can't see a use case where something would cost a single dollar. If it did, it'd happen so rarely that I'd probably not care about the attention to detail.
sradms0
Treehouse Project ReviewerNice. You could even trim this down if you wanted.
plural = ''
if num_tickets > 1: plural = 's'
zoltans
2,547 PointsThis was my way of thinking:
while tickets_remaining >= 1:
if tickets_remaining == 1:
print("There is {} ticket remaining.".format(tickets_remaining))
else:
print("There are {} tickets remaining.".format(tickets_remaining))
Is this okay?
Ewerton Luna
Full Stack JavaScript Techdegree Graduate 24,031 PointsEwerton Luna
Full Stack JavaScript Techdegree Graduate 24,031 PointsThat's a fine touch to the code. I really liked it! Thanks for sharing!!