In-class activity: Run a Python program in IDLE
- Install Python on your own computer from python.org – look for the Downloads link.
- You must use a computer, not a tablet.
- If you don’t have your own computer available in class, work with a partner in class and complete this activity later on your own computer.
- If you don’t have access to a computer at all, notify the instructor. It is possible to borrow a laptop from Dickinson for the semester if necessary.
-
We will be using a program called IDLE for writing and executing Python programs. IDLE was automatically installed when you installed Python. Open IDLE on your computer now.
-
Use
File | New Fileto create a new file. This will be a Python source code file containing our first Python program. Python files should have a name that ends in.py. Before typing the program in, save the file usingFile | Save As.... Name the filegreetings.py, and save it in yourclass01folder on OneDrive. - Type or paste this Python code into your file:
print("Greetings. I wonder if COMP130 will be fun AND useful AND enriching.") -
Save the file, then run the program via
Run | Run Module. - If you have time, paste in more code and experiment with it. For example, try this:
topic = input('What is/was your first year seminar topic? ')
print('Nice!!', topic, 'sounds interesting.')
Or this:
import math
x = math.sqrt(2)
print("By the way, did you know that the square root of 2 is", x, "?")
Or this:
a = 7
b = 24
c = a + b
print("Also, the sum of", a, "and", b, "is", c)
Don’t worry if you don’t understand the code. We’ll learn all about it this semester.