2 1 Jupyter notebooks This webpage is called a Jupyter notebook A notebook is a

2 1 jupyter notebooks this webpage is called a

This preview shows page 2 - 5 out of 20 pages.

2 1. Jupyter notebooks This webpage is called a Jupyter notebook. A notebook is a place to write programs and view their results, and also to write text. 2.1 1.1. Text cells In a notebook, each rectangle containing text or code is called a cell . Text cells (like this one) can be edited by double-clicking on them. They’re written in a simple for- mat called Markdown to add formatting and section headings. You don’t need to learn Markdown, but you might want to. After you edit a text cell, click the ”run cell” button at the top that looks like | or hold down shift + return to confirm any changes. (Try not to delete the instructions of the lab.) Question 1.1.1. This paragraph is in its own text cell. Try editing it so that this sentence is the last sentence in the paragraph. 2.2 1.2. Code cells Other cells contain code in the Python 3 language. Running a code cell will execute all of the code it contains. To run the code in a code cell, first click on that cell to activate it. It’ll be highlighted with a little green or blue rectangle. Next, either press | or hold down shift + return . Try running this cell: 2
Image of page 2
[4]: print ( "Hello, World!" ) Hello, World! And this one: [5]: print ( " \N{WAVING HAND SIGN} , \N{EARTH GLOBE ASIA-AUSTRALIA} !" ) , ! The fundamental building block of Python code is an expression. Cells can contain multiple lines with multiple expressions. When you run a cell, the lines of code are executed in the order in which they appear. Every print expression prints a line. Run the next cell and notice the order of the output. [6]: print ( "First this line is printed," ) print ( "then the whole " ) print ( "and then this one." ) First this line is printed, then the whole and then this one. Question 1.2.1. Change the cell above so that it prints out: First this line, then the whole , and then this one. Hint: If you’re stuck on the Earth symbol for more than a few minutes, try talking to a neighbor or a staff member. That’s a good idea for any lab problem. 2.3 1.3. Writing Jupyter notebooks You can use Jupyter notebooks for your own projects or documents. When you make your own notebook, you’ll need to create your own cells for text and code. To add a cell, click the + button in the menu bar. It’ll start out as a text cell. You can change it to a code cell by clicking inside it so it’s highlighted, clicking the drop-down box next to the restart () button in the menu bar, and choosing ”Code”. Question 1.3.1. Add a code cell below this one. Write code in it that prints out: A whole new cell! ♪♪ (That musical note symbol is like the Earth symbol. Its long-form name is \N{EIGHTH NOTE} .) Run your cell to verify that it works. [7]: print ( "A whole new cell! ♪♪" ) A whole new cell! ♪♪ 3
Image of page 3
2.4 1.4. Errors Python is a language, and like natural human languages, it has rules. It differs from natural language in two important ways: 1. The rules are simple . You can learn most of them in a few weeks and gain reasonable proficiency with the language in a semester. 2. The rules are rigid . If you’re proficient in a natural language, you can understand a non-proficient speaker, glossing over small mistakes. A computer running Python code is not smart enough to do that.
Image of page 4
Image of page 5

You've reached the end of your free preview.

Want to read all 20 pages?

  • Fall '17
  • Human height

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

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