21 11 Text cells In a notebook each rectangle containing text or code is called

21 11 text cells in a notebook each rectangle

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

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, and then click the ”run cell” | button or hold down shift + return . This sentence, for example, should be deleted. So should this one. 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," ) print ( "then the whole \N{EARTH GLOBE ASIA-AUSTRALIA} ," ) print ( "and then this one." ) First this line, 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. 3
Image of page 3
[7]: print ( "A whole new cell! \N{EIGHTH NOTE}\N{EARTH GLOBE ASIA-AUSTRALIA}\N{EIGHTH , NOTE} " ) A whole new cell! ♪♪ 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 21 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