Python Programming

Download Report

Transcript Python Programming

Python Programming
Introduction to programming using
python
Objectives
• We’re learning to develop basic code with
the use of the correct syntax and variables.
Outcomes
• Explain what syntax is and why it’s required.
• Explain the use of variables.
What is a program?
An organized list of instructions that, when executed, causes the computer to
behave in a predetermined manner. Without programs, computers are
useless. – Source – Webopedia – 2013
• You can think of a program like a recipe.
– It contains a list of ingredients called “Variables”.
– You can store many different types of information in a
variable such as:
• Data
• Text
• Images
– A variable on it’s own is like a bucket….
– You can get constant variables though…
What is a program?
Open up python IDE and type in the following:
Print (“hello world”)
What happens, when you press enter?
What is a program?
Open up python IDE and type in the following:
Print (“hello world”)
What happens, when you press enter?
What is a program?
Open up python IDE and type in the following:
5+9
What happens, when you press enter?
What is a program?
Open up python IDE and type in the following:
5+9
What happens, when you press enter?
Syntax Errors
Within python, there are a number of operators and functions which
are built into the language.
You’ve just seen how it can handle number, do any other operators
work? How do we subtract, divide or multiply. You give it a try!
Try printing other phrases, do they work?
Extension: Now type out: print (hello world)
What happens?
Syntax Errors
Extension: Now type out: print (hello world)
What happens?
SYNTAX ERROR
Like with English, programming languages have their own check
similar to a grammar check. When you run code it checks to see
whether it is in the form for the computer to compute. If you do
not do this the computer throws out an error like above.
Using Variables
• Variables are like a bucket, they’re used to store a number, data, text
or image. You can empty it or refill it as many times as you like.
• For example, to create a variable in python we might do the
following:
• Studentname = (“James”)
• This now means that the word James is stored in student name. You
can even print it to the screen by doing. Print (Studentname).
Using Variables
• You can do the same with numbers, for example:
•
•
•
•
Number1 = 10
Number2 = 20
Number3 = 20 + 10
Print (Number3)
Combine variables
• You can do the same with numbers, for example:
• Using number3 you can combine your sentence with the text you
stored in your variable. You could do the same with names or other
values. Notice the Comma separating it.
Using Variables / Syntax
Independent Task
•
Using what you have learnt see if you can print screen and evidence the
following for your teacher. You should evidence this by taking screen shots.
–
–
–
–
–
Show a syntax error and annotate it to explain it.
Show how to print text or numbers.
Show how to carry out calculations with numbers.
Show use of variables through either calculation or text.
See if you can make a sentence with the use of two variables.
Extension
Leading into next weeks lesson, you will have to know about different types of
variables and data types. See if you can research the types available and
examples of their use. You could really extend yourself by trying some of
the code…
Plenary
Self Assessment:
•
Your teacher has issued you with a self assessment sheet. You will have
today’s objects and outcomes on it.
Task
• Comment on the lesson. Talk about the positive experience you have had
and talk about things you need a little more help on. If you managed to get
onto the extension tasks, what have you found out?
Paper Toss Game – Delete this if you have an alternative task…
• Get your students to write down one thing they have learnt in the lesson on
scrap paper. Screw it up and throw it across the room. Once a piece of paper
has made it up to their side, they should unravel the paper and write
something different on it. Discuss what people have written down.