4. Running your first program (labo)
4. Running your first program (labo)
Hit the play button on the video next to this Jupyter notebook to start the video and follow
along as Andrew explains how to work through this lesson.
1. Hello, World!
Below is the code for the "Hello, World!" program that you saw the chatbot write in the
previous video.
To run the code, click anywhere into the cell (the box with the code inside), and then type
Shift + Enter (Shift + Return on a Mac) to execute.
Entrée [ ]:
print("Hello, World!")
Congratulations! You have just joined the millions of people who have started their computer
programming adventure by running this simple code!
2. Hello, you!
Let's create python code to say hello to you, instead of the world. Here are the steps to follow
along with Andrew in the video:
print("Hello, World!")
My name is Andrew
Paste the output code in the cell below using Ctrl+V (Command+C on a Mac)
Press Shift + Enter to submit your prompt
Once the chatbot has returned the code to you, you can copy and paste it into the cell below.
Only copy the code in the black box - don't copy any conversation text that the chatbot writes.
Entrée [ ]:
You should see Python print out "Hello," followed by your name above.
One other thing to notice here - when you run a code cell, the little square brackets to the left
of the cell will change to a number.
Entrée [ ]:
4. Comments in code
You may be wondering what the text is in the cells above that starts with the # hash or pound
symbol. This is a comment line. It tells Python that it can ignore anything that follows on that
line after the # symbol. Comments are used to help other humans understand what your code
does.
Try running the next cell by pressing Shift+Enter - what do you think will happen?
Entrée [ ]:
# THIS IS A COMMENT - PYTHON WILL IGNORE THIS LINE
The cell above runs just like the code you ran before - you saw the * appear to the left of the
cell, and then change to a number. But this time nothing appeared on the screen.`
A comment line is a valid piece of Python code. It tells Python to ignore what follows. Here,
Python followed that command exactly, running the code, ignoring the text, and because the
code had no output to return to you, it seemed like "nothing happened."
Click into the cell below and click Shift+Enter to run the code - make sure to ask yourself
what you think will happen first, and then see if you were right.
Entrée [ ]:
You can have multiple comment lines in your code, including one after another, and dispersed
throughout your code:
Entrée [ ]:
Entrée [ ]:
print("Hello, Andrew!)
You can ask the chatbot to help you fix this code:
print("Hello, Andrew!)
Fix the code in the next cell based on the chatbot's recommendation and run the cell using
Shift+Enter to see if the fix worked!
Entrée [ ]:
Entrée [ ]:
# Write code that answers the question "How are you feeling today?"
Entrée [ ]:
# Alter your code from the previous cell so that it will cause an error when you run it
Entrée [ ]:
# Ask an LLM to help you fix the error in the code in the previous cell (or fix yourself) and
# then type the corrected code on the next line: