Running a Python program
You should do this activity after you have downloaded the Lab 0 zip file
In PyCharm, your project contains all the folders and files for the semester:
These are in the top left corner:
This should match the organization of your cs110
folder in File Explorer
(Windows) or Finder
(MacOS).
Later in the semester, you should folders for each of your labs, homeworks, and projects inside of this same cs110
folder.
Opening a file
You can open files and directories by double-clicking on them.
- Double-click on the
hello
folder. - Double-click on the
hello.py
file.
You should see the hello.py
program:
The main block
Every program has to start somewhere. In Python, we call this the main block. This is where Python starts when it runs your code.
We will explain more about the code here later. Don’t worry about learning what all of this means.
Running a program
To run a program, find its main block
and click the green triangle to the left of it.
Select Run 'hello'
.
You will see a window open at the bottom of PyCharm that has the output of the program:
That is all this program does! It prints Hello! Welcome to CS 110!
.
Every time a program finishes successfully, Python will print Process finished with exit code 0
.
Running another program
- Double-click on the
intro
folder. - Double-click on the
introduce-yourself.py
program.
You now have two programs open, each one in a separate window. You can click on the tabs at the top to switch between the two files.
Run it by finding the main block
and clicking on the green triangle next to it. You should see this in the window at the bottom:
Here, Python is waiting for input, meaning you need to type your name. Click in that window, type something, and press enter.
Stop and re-run
Run the intro program again by clicking on the green triangle next to the main block
. Take a look at the window on the bottom again:
On the bottom left, you will see:
a red square
— if you press this, it stops your program immediatelya green curved arrow
— if you press this, it stops your program and re-runs it from the beginning
Try out these buttons to see what they do.