lab02October 8, 20181Lab 2: Data TypesWelcome to Lab 2!Last time, we had our first look at Python and Jupyter notebooks. So far, we’ve only usedPython to manipulate numbers. There’s a lot more to life than numbers, so Python lets us representmany other types of data in programs.In this lab, you’ll first see how to represent and manipulate another fundamental type of data:text. A piece of text is called astringin Python.You’ll also see how to invokemethods. A method is very similar to a function. It just looks alittle different because it’s tied to a particular piece of data (like a piece of text or a number).Last, you’ll see how to work with datasets in Python --collectionsof data, like the numbers 2through 5 or the words "welcome", "to", and "lab".Initialize the OK tests to get started.In [1]:fromclient.api.notebookimportNotebookok=Notebook('lab02.ok')_=ok.auth(inline=True)=====================================================================Assignment: Lab 2: Data TypesOK, version v1.12.5=====================================================================Successfully logged in as [email protected]Deadline: If you are not attending lab physically, you have to complete this lab and submit byWednesday, August 29th before 8:59 A.M. in order to receive lab credit. Otherwise, please attendthe lab you are enrolled in, get the check-off with your (u)GSI or learning assistantANDsubmitthis assignment by the end of the lab section (with whatever progress you’ve made) to receive labcredit.Submission: Once you’re finished, select "Save and Checkpoint" in the File menu and thenexecute the submit cell below (or at the end). The result will contain a link that you can use tocheck that your assignment has been submitted successfully.In [ ]:_=ok.submit()1
21. Review: The building blocks of Python codeThe two building blocks of Python code areexpressionsandstatements. Anexpressionis a piece ofcode that• is self-contained, meaning it would make sense to write it on a line by itself, and• usually has a value.Here are two expressions that both evaluate to 335 - 2One important form of an expression is thecall expression, which first names a function andthen describes its arguments. The function returns some value, based on its arguments. Someimportant mathematical functions areFunctionDescriptionabsReturns the absolute value of its argumentmaxReturns the maximum of all its argumentsminReturns the minimum of all its argumentspowRaises its first argument to the power of its second argumentroundRound its argument to the nearest integerHere are two call expressions that both evaluate to 3abs(2 - 5)max(round(2.8), min(pow(2, 10), -1 * pow(2, 10)))All these expressions but the first arecompound expressions, meaning that they are actuallycombinations of several smaller expressions.2 + 3combines the expressions2and3by addition.
Want to read all 8 pages?
Previewing 3 of 8 pages Upload your study docs or become a member.
Want to read all 8 pages?
Previewing 3 of 8 pages Upload your study docs or become a member.
End of preview
Want to read all 8 pages? Upload your study docs or become a member.