Getting Started With Python
Getting Started With Python
As you have learned, there are many programming languages out there. We are going to have a look
Aim: Try
at some Python programming code. The reasons for choosing this language include:
some Python
programming.
1. It is relatively easy to understand – there are not too many fiddly rules to remember.
2. Python is a cross-platform language. It can be used on many devices and operating systems.
3. You can create and test some simple scripts using the website www.repl.it.
4. There are a large number of libraries available online. These are ready-written programs that carry out common tasks.
5. Python is used by many of the biggest tech companies.
Having said this, programming languages have many similarities. Once you’ve got your head around the basics of programming
it’s much easier to learn new languages as and when you need to.
a. Navigate to the website https://repl.it/languages/python3 (or visit www.repl.it and search for Python3). It is better to set
up an account so that you can save your work.
b. In a new session, type the code print ('Hello, world!') in the coding
window. This is the white window on the left of the screen.
c. Click the Run button (or press ‘Ctrl + Enter’). The Run button briefly
turns to Stop. This can be used to halt programs.
Extension
Try achieving this last task with one print statement.
Use \n to create a new line in your text.
CoP046 – Algorithms & Programming: Python ORB Education. Visit www.orbeducation.com for a range of quality teaching resources.
Getting Started with Python (page 2)
Note 1: In Python, a single equals sign (=) assigns a value to a variable. Line 1 could be read as ‘The variable first_name is
assigned the value Sarah’.
Note 2: Python is a case sensitive language. This means that capital letters make a difference to the program. In the
example above, ‘first_name’ would be a different variable to ‘First_Name’. Also, typing ‘Print’ with an upper-case P
would not work. The line spaces make no difference, however. You can add these to make your programs easier to
read. Other spaces (e.g. either side of the + and = symbols) generally don’t have an effect, but spaces and tabs at
the start of a line definitely do have an effect on your Python programs.
a. Type the program into repl.it and run it. Write down the exact output that appears in the console.
_____________________________________________________________________________________________________
b. We want to add a space between the first name and the last name. We can do this by inserting the code + " " + between
the first_name and last_name variables in line 4, in place of the single + symbol. Edit line 4 and rerun the program.
Carefully write out the new line 4 below.
_____________________________________________________________________________________________________
Note: The ‘+’ symbol joins two words (or strings) together. We are therefore now joining the first name, a space and the
last name together.
c. A variable is a space in the computer’s memory. Think of it like a box where you can keep information until it’s needed.
Write down the names of the three variables used in this program.
_____________________________________________________________________________________________________
d. We could make this program more efficient by getting rid of the full_name variable completely. Change line 6 to the code
shown below. Delete the line of code that is no longer required.
e. Enter the title “07.2 Fixed Names” into the name box at the top. Click the Save button.
f. You can access your saved programs at any time by logging in and using the my repls link in the top-right. Your teacher may
also want you to copy and paste the code into a document (with the title above it) for marking purposes.
CoP046 – Algorithms & Programming: Python ORB Education. Visit www.orbeducation.com for a range of quality teaching resources.
Getting Started with Python (page 3)
c. You should see an output something like the one shown here
(with your own name, of course).
f. Make this code more efficient by removing the full_name variable again.
g. Save your program.
Extension - Numbers
What happens if you enter numbers into the console rather than names? Is it possible to input two numbers and total them, so
that 1 + 2 = 3 rather than 12? We will look at this in the next task.
CoP046 – Algorithms & Programming: Python ORB Education. Visit www.orbeducation.com for a range of quality teaching resources.