Lesson 1 WIP - kingsmeadspecialisms.com

advertisement
Lesson Objectives
http://www.brainpop.co.uk
Watch
Username: kmeadsch
Password: ict
Web address
Activity: write an algorithm for
putting on your shoes
Python
Computer Programming in Python
During this term you will learn the exciting programming tool called Python. This is based on
programming languages like C that are used to create many popular programs that you use
everyday.
Objectives
Develop a fundamental understanding of the basic design of a programming language
• Design and create a computer program
• Identify key coding elements and explain their use
Want Python at home?
Python is free http://python.org/download/
Homework
During your lesson you will have used some key terms and
programming language. Update the programming dictionary
below.
Homework is due in the next lesson unless your teacher tells you
otherwise.
Optional - Starter
• Robot Maze – load the Excel file
Write down a list of instructions that you
would give to get a robot to the exit
You can do this any way you would like.
What’s going on
• When you launch Python IDLE, you should now see the Python
Shell window, with a menu like the following, though the text
may be slightly different:
Choose file NEW
• Look at the Python Shell. ...
This is the
Edit Window
Using shell
Shell processes instructions a line at a time.
Python shell starts with >>> Let’s think of this as a happy dog’s wagging tail!
Python is happy to see you! Unlike a dog it will ALLWAYs follow your instructions.
But like a dog it can only understand set commands,
So when you type Python acts like a dog and only pays attention to COMMANDS that it already is
trained to do.
Owner says “Good dog perhaps we’ll go for a walk later!”
The dog hears “ blah blah blah blah blah blah blah WALK blah!
Look at the Python Shell. ... In the Shell the last line should look like
>>>
The >>> is the prompt, telling you Idle is waiting for you to type something. Continuing
on the same line enter
6+3
Be sure to end with the Enter key. After the Shell responds, you should see something
like
>>> 6+3
9
>>>
The shell evaluates the line you entered, and prints the result. You see Python does
arithmetic. At the end you see a further prompt >>> where you can enter your next
line....
In idle type
>>>print ("Hello, World!“)
Press enter to see what
happens
Now type
>>> x=input ("What is your name?")
Press enter -What happens?
Enter some information!
Now type
print(x)
Press enter -What happens?
In EDITOR
• There are three types of
variables:
• Integers – whole numbers
• Floats – decimals
• Strings – text & symbols
Look at this SCRIPT
What does it do?
(50)
Which variable in
this script WON’T
print out?
String concatenation without '+' operator in python
one = 1
two = 2
three = (one) + (two)
# what does this script do?
print (three)
message1 = ("hello")
message2= ("world")
quote = (message1) + (" ") + (message2)
# This script concatenates – what do you think this means?
print (quote)
Have a go! – Use
the editor .
Save file as:
concatenate
F5 to run
Our first program
• Open Python
• Copy out the following short program
• Prior learning [ you should have done Blockly Turtle Flower]
Click F5 to see
what happens
Video link
Our first program
• Open Python
• Prior learning [ you should have done Blockly Minecraft Dude]
• Copy out the following short program
• Link
•
Click F5 to see
what happens
http://www.kingsmeadspecialisms.com/ICT/VIDEO/Video_Catalogue/Catalogue_files/py_code_for_loop_using_a_variable-to-step.swf
Video link
new commands
The turtle can turn any angle you wish
The command are: left(x) right (x) forward(x)
You put any number between 1 – 360 in the place of x
the parameter x is a numeric value
Color=(“y”)
the perameter here is a text strring e.g blue, yellow
Begin_fill() and End_fill() are primitive COMMANDS
What do you think they do?
Turtle – Using the Fill tool
The following flowchart
illustrates how the while
loop works.
http://www.kingsmeadspecialisms.com/ICT/VIDEO/Video_Catalogue/Catalogue_files/py_turtle_while_true_colour_fill_loop.swf
Task
• Create a program which draws a hexagon
Hint, to work out the angle to turn do the following calculation
Angle = 360/ number of sides
Programming is all about trial and error - don’t stop trying just
because it doesn’t work first time!
Before we continue
• Lets get into the habit of consolidating what we learn.
Fill in your Python “Programming Dictionary”
Key works
•
•
•
•
•
•
•
Function AKA Procedure AKA Subroutine
Code
Algorithm
Iterate
Variable
Read questions carefully – there are two trick questions
Process
Bug
Take this simple Quiz
Download