Introduction to Python
IDLE
At QE2 we use IDLE to write Python programs.
IDLE can be downloaded for Windows or MacOS from python.org
When you open IDLE, the first thing you will see is the Shell.
The Shell
This is a window that allows you to type individual python commands and the shell will execute them.
Try typing in the following code (then press enter) to see what happens...
print("Hello World!")
or try this...
8 + 4
If you want Python to do more than one command at a time you will need to write a program.
Creating Programs
To write a program in Python you will need to open a New File... (from the File menu).
This will open a new window where we can write multiple lines of code.
(Top Tip: Split your screen so you have both windows open next to each other).
Try typing the following code into the new window...
print("Enter your first name")
firstname = input()
print("Hello ", firstname)
You will now need to Save... your program.
Call it: demo.py
You can now RUN your program (press F5).
You will see the output in the shell. When it asks you enter your name, type it in and press enter.
Adding Comments
Sometimes you will want to write comments in your code that explains what some of the code does.
You might also use comments to write reminders to yourself of things you still need to do.
In Python we use the # symbol to say what comes next is a comment.
When the IDE sees the # symbol it ignores what comes next.
Watch the video below introducing Python
Key Words
Algorithm
A set of step-by-step instructions that solve a problem.
Code
An instruction written in a way that a computer can understand and follow.
Program
A set of instructions for a computer to follow.
IDE
Integrated Development Environment - A computer application that allows programmers to write and test programs, for example IDLE is used to write and test Python programs.
Comment
Text that is added to your program that the computer will ignore. Comments are used to explain what code does.