lab02.pdf - lab02 1 Lab 2 Data Types Welcome to Lab 2 Last time we had our first look at Python and Jupyter notebooks So far weve only used Python to

lab02.pdf - lab02 1 Lab 2 Data Types Welcome to Lab 2 Last...

This preview shows page 1 - 3 out of 8 pages.

lab02 March 16, 2018 1 Lab 2: Data Types Welcome to Lab 2! Last time, we had our first look at Python and Jupyter notebooks. So far, we’ve only used Python to manipulate numbers. There’s a lot more to life than numbers, so Python lets us represent many 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 a string in Python. You’ll also see how to invoke methods . A method is very similar to a function. It just looks a little 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 -- collections of data, like the numbers 2 through 5 or the words "welcome", "to", and "lab". Initialize the OK tests to get started. In [1]: from client.api.notebook import Notebook ok = Notebook( ' lab02.ok ' ) _ = ok . auth(inline = True ) ===================================================================== Assignment: Lab 2: Data Types OK, 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 by Wednesday, 1/24 9:59am in order to receive lab credit. Otherwise, please attend the lab you are enrolled in, get the check-off with your (u)GSI or learning assistant AND submit this assignment by the end of the lab section (with whatever progress you’ve made) to receive lab credit. Submission : Once you’re finished, select "Save and Checkpoint" in the File menu and then execute the submit cell below (or at the end). The result will contain a link that you can use to check that your assignment has been submitted successfully. In [2]: _ = ok . submit() <IPython.core.display.Javascript object> 1
Image of page 1
<IPython.core.display.Javascript object> Saving notebook... Saved ' lab02.ipynb ' . Submit... 100% complete Submission successful for user: [email protected] URL: 2 1. Review: The building blocks of Python code The two building blocks of Python code are expressions and statements . An expression is a piece of code 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 3 3 5 - 2 One important form of an expression is the call expression , which first names a function and then describes its arguments. The function returns some value, based on its arguments. Some important mathematical functions are Function Description abs Returns the absolute value of its argument max Returns the maximum of all its arguments min Returns the minimum of all its arguments pow Raises its first argument to the power of its second argument round Round its argument to the nearest integer Here are two call expressions that both evaluate to 3 abs(2 - 5) max(round(2.8), min(pow(2, 10), -1 * pow(2, 10))) All these expressions but the first are compound expressions , meaning that they are actually combinations of several smaller expressions. 2 + 3 combines the expressions 2 and 3 by addition.
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 8 pages?

  • Fall '17

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors