Programming

Quick links

3.1

Programming

3.2.1

Data types

3.2.2

Programming concepts

3.2.3

Arithmetic operations

3.2.4

Relational operations

3.2.5

Boolean operations

3.2.6

Data structures

3.2.7

Input/output and file handling

3.2.8

String handling operations

3.2.9

Random number generation

3.2.10

Subroutines

3.2.11

Structured programming

3.2.12

Robust and secure programming

3.3.13

Classification of programming languages

 

Getting started with Python at Stanground Academy

 

Virtual box

Session 1 – Introduction to Python

Image result for eric idleOpen the IDLE Python GUI which is the Integrated Development Environment (IDE) (called IDLE after Eric Idle who is a Python). 

First, you will have to open “Virtual Box”. You will find it in your “All Programs” Menu under ICT.

There may be a new folder called "Virtual Box" and the version of Virtual Box that you are to load is "Sta-client".

Text Box: Key terms  Key terms will be explained or described in the boxes on the right hand side of the page such as this one.

 

 



Text Box: Virtual box   Virtual box is a temporary computer within the real computer that you are using so that you can use additional software such as Python.  Accept all of the messages by pressing OK until a new copy of Windows is loaded.From the new start button in the virtual version of Windows you can select Start – All programs – Python 3.2 and then IDLE.

Text Box: Progress  Always record your progress on the back page of this booklet as you work through each of the exercises.Using the IDLE in “Interactive Mode”

Open Python as described above and you will see this:

This is the “Python Shell” where you can type in instructions to Python that will be carried out immediately.

Hello World

All programmers start with the program “Hello world”. It’s very much of a rite of passage.

Exercise 1

Copy and run the following program in Python in interactive mode (first Window in IDLE).

print(‘Hello World’)

(case sensitive, as are all commands in Python)

You will hopefully see the message    Hello World as shown below.


print (“xxx”) will work as will print  (‘xxx’)  (N.B. speech marks)
but Print (“xxx”) won’t because Python does not accept capitals in commands such as print

 

Exercise 1a

Change the program so that it prints out:
Pleased to meet you
Text Box: Student answer

Exercise 1b

Write a program to display using apostrophes rather than speech marks:
This is Paul's first program
The apostrophe makes this trickier than it first may seem.


Use a combination of “ and  ‘ characters try it and see. Is there a difference?

Writing Python programs - Session 2 - Using IDLE and Saving Programs

When using the IDE (IDLE) in “Script Mode” IDLE is in effect a word processor for Python programmers. Using “interactive mode” is fine if you want to look at one line programs or use notepad to write programs and copy them into IDLE but for real programs you need to write and save your program and then run it. 
Open Python and you will see the IDLE window

Now select File and then select New Window.  A new window will open looking just like the one below.

It is slightly different from the interactive window as it is currently untitled and has no Shell menu tab.  This window is called a “Script Window” and a new one is opened for each new program you want to write.

Now type into this new window:   print (“Hello New World”)   and press enter.

Hopefully nothing will happen except the cursor moves to a new line.
Now go to the Run Menu and the select Run Module (you can just press F5 at any time to run your program).
You will be asked to save the program save it into a folder as shown below.  You are working in a Virtual computer so take care when you save. If you save to drive C: then when you exit all your work will vanish.  Any work lost in this way cannot be recovered so it is up to you to make sure that all your work is saved correctly.
You must select “Computer”

… and then Drive H:

I saved it into a Folder I made in My Documents that I called Python.

Text Box: Syntax  Syntax is simply the rules of the language.Name your files with the name of the exercise that you are attempting so that you can keep a close check on your progress.
Note that the PC is supposed to save it as a type .py this means the PC recognises it as a Python File.  When you run Python on your PC at school you will have to add the .py yourself.  You will know if you need to do this as your program in IDLE will change from multi coloured to all black if it doesn’t have the correct extension suffix.
Once you have saved it, if necessary press F5 again and the program will run.  Below you should see what happens.

Exercise 2a

Try typing in the following program: Remember the syntax is important and be careful when you use capitals.  Type in the following

Text Box: Case sensitive  It is very important to know that Python is case sensitive. Print() is not the same as print() and only print() works correctly to put text on the screen.Run the program by using menu:  Run – Run Module (or F5.
Save to your Python folder when prompted and you should see what is shown below.

Exercise 2b

Try this, the \n command at any point in a line of text will force a new line:

Text Box: Academy Address  The Stanground Academy  Peterborough Road  Peterborough  PE7 3BYYou should see something like this:

Exercise 2c

Write a program to correctly display the address of the academy in a single line of code.

Text Box: Student answer

Writing Python programs - Session 3 - Interactive Programming

We have run some simple programs now we will look at how to make the programs interactive.  By interactive we mean making a program wait for a user to input some data and then respond in some way.
Text Box: Comments  Comments are used to allow a programmer to add notes to the program so that others will understand what he is doing.The first command we will look at is the “input” command (note; this is still lower case).
Copy in the following program (note; variables are not normally given capital letters in Python e.g. we use name not Name.  This is just a convention and has no effect on the way the program runs.)


I have done this below with some comments using the # sign.
Students will be asked to add comments to their programs when you do the controlled assessment.  The example below also demonstrates that too many # comments can actually make a program harder to read

Run the program (F5) and when prompted save to your Python Folder; it should look like the example below.  I used the name “John” when asked; you can use what you like.

Text Box: Flowcharts  From time to time flowcharts will be included so that you can see what an algorithm looks like as code and as a flowchart.

 

 

 

 

 

Exercise 3a

Write a program that asks for your favourite type of music and then replies I love {your choice} as well.
e.g.

Text Box: Student answer

Exercise 3b

Write a program that asks for your first name, then asks for your last name and finally prints out a greeting including your full name. e.g.


There are two ways to achieve this one uses a blank space “ “ the other involves investigating the difference between using the + (concatenating) and the , to separate the variables.  Try both of these now.  We will look into the both these methods in more detail in later lessons. Extension: (exercise 3c) get Python to ask for your favourite subject as well.

Text Box: Student answer

3.1 Fundamentals of algorithms

3.2 Programming

3.3 Fundamentals of data representation

3.4 Computer systems

3.5 Fundamentals of computer networks

3.6 Fundamentals of cyber security

3.7 Ethical, legal and environmental impacts of digital technology on wider society, including issues of privacy

3.8 Aspects of software development

Glossary and other links

Glossary of computing terms.

AQA 8520: The 2016 syllabus

AQA pseudocode guides