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

My code also works but its diferent, is there a diference in practice?

num_tickets = int(input("Hello {}, how many tickets would you like to buy?  ".format(name)))

Instead of:

num_tickets = input("Hello {}, how many tickets would you like to buy?  ".format(name))
num_tickets = int(num_tickets)

It works, but I have slightly tested it only, in the longrun is it or isnt it the same as Craig's?

Cheers.

1 Answer

HI Nuno,

You're code is, in substance, the same as Craig's. The only difference is that you are doing the input and type casting on one line.

It is possible that your way might be fractionally faster due to you only performing an assignment once, but without knowing exactly how the particular interpreter converts your code to machine code, it's difficult to determine whether there is actually any performance difference.

The flip side is that there is a fractional increase in code complexity. By doing two things on one line instead of one, it might be slightly slower to debug any error or slightly slower to refactor if you decide you wanted to modify part of the behaviour of that line.

This is a tiny example of the typical tradeoff we make as programmers, balancing execution performance and programmer efficiency.

Hope that helps,

Alex