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

Was there a reason that he coerced the integer in a new line instead of doing it on one line?

For example, Craig formats his line as:

number_of_tickets = input("Hey {}, how many tickets do you want to buy? ".format(name)) number_of_tickets = int(number_of_tickets)

Is there a reason that we don't do it all in one line like:

number_of_tickets = int(input("Hey {}, how many tickets do you want to buy? ".format(name)))

This was I had come up with in the test, and it seems to work fine, so is there a reason to choose one method over the other?

Thanks so much!

1 Answer

Steven Parker
Steven Parker
243,266 Points

Sometimes the course examples break things down into individual steps to help make what the code is doing clear.

As you continue in your studies, you'll find it increasingly common to come up with ways to optimize the examples. That's just evidence of your progress.