Вы находитесь на странице: 1из 17

Lesson 1 COMPUTING

Introduction to Python
Learning to Program
What you need to be good at
Computing?
What you should be good
at?

Mathematics
Science (Physics)
Problem Solving
WHAT IT INVOLVES

Click to watch - The impact of


Computing in society

ICT and Computing together allows


you to get the most amazing careers.
What is Python?
Its a third generation language
Its an interpreted language

Third Generation

Second Generation

First Generation

Hardware
What is a program then?
Sequence of instructions
Input
Process
Math
Branches: (Conditional execution)
Loops: (Repetition)
Output

THATS ALL FOLKS


Whoops!
Programming involves making lots of mistakes.
These are called bugs.
There are three types

Syntax errors
Runtime errors
Semantic errors
Programming and Debugging are the same
thing!
Only superheroes can write more than a few
lines of code without making a mistake.
SO
We write a tiny program, fix it, write a tiny bit
more, fix that,

.. and so on .
.. forever
Lets start using Python

Today will are going to try some


simple programming codes.
IDLE
IDLE is the graphical user interface that comes with
Python.
Once inside the IDLE shell select File and New Window
to open the text editor.

TIP: When saving your file


remember to add the .py
extension to your file.

It will still run without it


but by adding this, IDLE will use
syntax highlighting which will
make your code easier to read.
Task 1
1. Output to the screen
Hello World
All programmers start with the program hello world. Its very much of a rite of passage.

Copy and run the following program in Python.


print('Hello World!')
You will hopefully see the message Hello World!

Type the code

Save it &
Press F5

Look at the
shell
Task 2
Task 2a
Change the program so it says - Pleased to meet
you.

Task 2b (HINT - use \n)


Write a program that says:
This is a
computer program
that prints on several lines
Challenge Exercise
Write a program to say

This is John's first program

The apostrophe makes this trickier than it first


may seem (Hint: Find out about escape
characters in Python).
Storing Data in Variables
We use variables in our programs to store data. Each variable has a name and stores
data of a certain type (string, integer, real etc).

String is the programming term for text (i.e. letters, numbers and symbols).
Variable names can contain letters and numbers but should always start with a letter.
We assign a value to a variable using =

Task 3
Copy and run the following program:
name='Bob'
print('Hello '+name)
Try this out
name='Bob'
name=name+'by'
print('Hello '+name)
This will print Hello Bobby

Whereas
name='Bob'
name=name+name
print('Hello '+name)
Will print Hello BobBob
Challenge Time
Complete the following program so it uses the
variables to print out the cat sat on the mat.
Remember you will need to add spaces.
E.g.
word1='the'
word2='cat'
word3='sat'
word4='on'
word5='mat'
Lesson 2 Task 4 Extension - Inputting
Data
We can now look at starting to make our
programs interactive. We are going to take in
input from the user using the input function.

name=input('What is your name?')


print('Hello '+name)
Why Computing?
If you would like a future in computers, this is
the course for you.

You should want to develop your skills outside


of the class room.
You should be good at maths and physics.
Never give up on a problem.

Вам также может понравиться