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 Gather Information

Enrica Fedeli-Jaques
Enrica Fedeli-Jaques
6,773 Points

Is assigning the int in a different place ok? it works

Hi,

Is it possible that this is less smelly than Craig's code? ;)

ticket_request=input("Hi {}, how many tickets would you like to buy? ".format(user_name)) total_price=int(ticket_request)*TICKET_PRICE

rather than assigning the int in a separate line?

This seems fine, but be sure to do this every time when you need to re-use ticket_request. If you do need to use it in other calculations, it'll be easier to turn it in to an integer in a separate line.

1 Answer

Steven Parker
Steven Parker
231,271 Points

It works, but as "ad15" suggested, you would need to call "int" again each time "ticket_request" was used in the code. So doing it just once immediately on input might help keep the code "DRY" if the functionality is extended in the future.

And from the standpoint of clarity, it also changes what "ticket_request" represents. Does it make more sense for it to be a string, or a numeric value?

If you just want to avoid a separate line, you can combine the input and the conversion in one:

num_tickets = int(input("How many tickets would you like, {}?  ".format(name)))