BerkeleyXData8.1x lab01.html - Lab 1 Introduction to Python Welcome to Lab 1 Each week you will complete a lab assignment like this one In this lab

BerkeleyXData8.1x lab01.html - Lab 1 Introduction to Python...

This preview shows page 1 - 4 out of 19 pages.

Lab 1: Introduction to PythonWelcome to Lab 1! Each week you will complete a lab assignment like this one. In this lab, you'll get started with the Python programming language through numbers, names, and expressions.As you go, please regularly select Save and Checkpointfrom the Filemenu below the Jupyter logo to save your work.1. NumbersQuantitative information arises everywhere in data science. In addition to representing commands to print out lines, expressions can represent numbers and methods of combining numbers. The expression3.2500evaluates to the number 3.25. (Run the cell and see.)In [1]:3.2500Out[1]:3.25Notice that we didn't have to print. When you run a notebook cell, if the last line has a value, then Jupyter helpfully prints out that value for you. However, it won't print out prior lines automatically. If you want to print out a prior line, you need to add the printstatement. Run the cell below to check.In [2]:print(2)342Out[2]:4Above, you should see that 4 is the value of the last expression, 2 is printed, but 3 is lost forever because it was neither printed nor last.You don't want to print everything all the time anyway. But if you feel sorry for 3, change the cell above to print it.1.1. ArithmeticThe line in the next cell subtracts. Its value is what you'd expect. Run it.In [3]:3.25 - 1.5
Background image
Out[3]:1.75Many basic arithmetic operations are built in to Python. The textbook section on Expressions describes all the arithmetic operators used in the course. The common operator that differs from typical math notation is **, which raises one number to the power of the other. So, 2**3stands for $2^3$ and evaluates to 8.The order of operations is what you learned in elementary school, and Python also has parentheses. Forexample, compare the outputs of the cells below. Use parentheses for a happy new year!In [4]:2+6*5-6*3**2*2**3/4*7Out[4]:-724.0In [5]:2+(6*5-(6*3))**2*((2**3)/4*7)Out[5]:2018.0In standard math notation, the first expression is$$2 + 6 \times 5 - 6 \times 3^2 \times \frac{2^3}{4} \times 7,$$while the second expression is$$2 + (6 \times 5 - (6 \times 3))^2 \times (\frac{(2^3)}{4} \times 7).$$Question 1.1.1.Write a Python expression in this next cell that's equal to $5 \times (3 \frac{10}{11}) - 49 \frac{1}{3} + 2^{.5 \times 22} - \frac{7}{33}$. That's five times three and ten elevenths, minus 49 and a third, plus two to the power of half of 22, minus 7 33rds. By "$3 \frac{10}{11}$" we mean $3+\frac{10}{11}$, not $3 \times \frac{10}{11}$.Replace the ellipses (...) with your expression. Try to use parentheses only when necessary.Hint:The correct output should be a familiar number.In [6]:5*(3+10/11)-(49+1/3)+2**(5*22)-7/33Out[6]:1.298074214633707e+332. NamesIn natural language, we have terminology that lets us quickly reference very complicated concepts. We don't say, "That's a large mammal with brown fur and sharp teeth!" Instead, we just say, "Bear!"
Background image
Similarly, an effective strategy for writing code is to define names for data as we compute it, like a lawyer would define terms for complex ideas at the start of a legal document to simplify the rest of the writing.
Background image
Image of page 4

You've reached the end of your free preview.

Want to read all 19 pages?

  • Fall '17
  • Human height

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