From the course: Python for JavaScript Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Port the code

Solution: Port the code - Python Tutorial

From the course: Python for JavaScript Developers

Start my 1-month free trial

Solution: Port the code

(upbeat music) - [Instructor] So, how did it go? Our challenge for this video was to port a small JavaScript program into Python. And kind of paying attention to conventions is always a good idea. So here I begin by importing decimal from the Decimal module. And this enables me to get that precise decimal type we talked about. And then on line three, I use all caps in order to indicate that this is a constant. For all three of these, I actually use all caps if you notice because I don't change these definitions in the runtime. So basically we have user name. Then we have credits. Then we have items in cart. And in line four for credits, you'll see me using the decimal type. Then in line seven, we have get first item, which takes a user, credits, items, and returns that interpolated string. So it interpolates the items zero and user and credits. It uses that F string syntax we talked about. Finally, in line 10…

Contents