john palmer - worc inputs/cas... · •plan simple algorithms using flowcharts ... use different...

81
John Palmer Faculty Head: IT, Computing & Business – The Chase School, Malvern CAS Hub Leader: “Three Counties” Hub (Hereford, Worcs and Gloucs) CAS Master Teacher Regional Coordinator: Network of Excellence (Secondary) @johnny__palmer [email protected]

Upload: vungoc

Post on 09-Mar-2018

222 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

John Palmer Faculty Head: IT, Computing & Business – The Chase School, Malvern

CAS Hub Leader: “Three Counties” Hub (Hereford, Worcs and Gloucs)

CAS Master Teacher

Regional Coordinator: Network of Excellence (Secondary)

@johnny__palmer

[email protected]

Page 2: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Overview

Housekeeping

Introduction

Session 1

Session 2

Plenary

Session 3

Homework

Webinar

Questions

Feedback

• Looking to teach coding as part of Computing, (most probably

GCSE)

• Little / old coding experience (maybe in Python)

• Not sure what the exam boards require pupils to know

• This is a functional introduction to coding in Python (we can’t

cover everything in 2 hrs....)

• There will be follow – up for those interested in developing

their use of Python for GCSE

• NB - not just about learning the Python coding language, it’s

also about HOW you teach Python to children...

Why are you here?

Page 3: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Why Python?

• It’s cool

• It’s Open Source

• It’s a great introductory language

• It’s easy to learn – the students like it

• A “console” based language (not visual, but good for teaching the basics...)

• Loads of free learning resources / books

• The Computing curriculum is being “crowd-sourced”

• Supported by most (all) exam boards?

• Try not to worry to much about which language you are using, it’s not just about that after all....

• It is however an important choice....

• Many people are using Python successfully in the classroom for GCSE Computing

Page 4: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Python 3 vs Python 2

• Python 2 is the status quo, Python 3 is the present and future of the language

• There will be no new major releases for Python 2 beyond 2.7. “the 2.x line will only receive bugfixes, and new features are developed for 3.x only.” – python.org

• Graphical User Interfaces can already be created using Tkinter which already comes with Python 3. PyQt4 already supports Python 3.

Page 5: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Overview

Housekeeping

Introduction

Session 1

Session 2

Plenary

Session 3

Homework

Webinar

Questions

Feedback

Learning Outcomes:

By the end of this course you will be able to:

• Plan simple algorithms using flowcharts

and pseudocode

• Code simple algorithms using Python

• Understand and use the three basic

programming constructs used to control the flow

of a program

Introduction

Page 6: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Overview

Housekeeping

Introduction

Session 1

Session 2

Plenary

Session 3

Homework

Webinar

Questions

Feedback

• Would you expect 16 year-olds to pass GCSE Maths after 120 lessons?

Session 1: Designing algorithms

Page 7: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

In an ideal world…

• Primary school would teach basic computational

thinking – eg instructions / sequences

• KS3 would introduce concepts regarding program

flow control and data structures

• KS4 would use these skills to investigate more

advanced coding topics, (file handling, recursion,

etc.)

Page 8: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

The reality…

• Pupils start Year 10 with little or no coding

experience

• GCSE Computing represents a significant

change from what most teachers have been

doing (eg GCSE ICT / DiDA, OCR Nats...) and

trained for (Maths / ICT / DT....)

Page 9: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Typical GCSE expectations

• For the OCR GCSE Coding Based Controlled Assessment (and

tested in the exam):

(a) identify and use variables, operators, inputs, outputs and assignments

(b) understand and use the three basic programming constructs used to control

the flow of a program: Sequence; Conditionals; Iteration

(c) understand and use suitable loops including count and condition

controlled loops

(d) use different types of data including Boolean, string, integer and real

appropriately in solutions to problems

(e) understand and use basic string manipulation

(f) understand and use basic file handling operations: open, read, write and close

(g) define and use arrays as appropriate when solving problems.

Page 10: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Typical GCSE expectations

Important Newsflash

It’s less about being able to “code in

a certain language” and more about

being able to “think Computationally

and solve problems”

Page 11: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

KS3 building to GCSE

• GCSE Computing courses require pupils to:

– Understand the operation of algorithms

– Design algorithms

– Produce algorithms to solve problems

• CAS curriculum for KS3:

– “A student should understand what an algorithm is,

and what algorithms can be used for”

Page 12: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Developing algorithms

• Pupils we teach to GCSE will need to develop

algorithms that use:

– Sequence

– Selection

– Iteration

• …maybe we should start teaching them this

earlier!

Page 13: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Sequence

• The starting point for all algorithms

• Series of instructions one after each other

Pick up cup

Drink coffee

Put down

Page 14: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Selection

• Useful algorithms will need to react to

conditions that occur

Is mug empty?

Drink coffee

Put down

Nibble biscuit

Page 15: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Iteration

• Repeat parts of an algorithm to approach the

desired outcome

Pick up mug

Is there coffee in mug?

Put down

Drink coffee

Page 16: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Planning using flowcharts

• Graphical representation of

algorithm sequence.

• Good flowchart design must:

– Begin and end with the same shape

– Connect all steps with a direction

arrow

– Be evenly spaced

– Have clear and concise descriptions.

Page 17: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Planning using pseudo code

• This is a list of instructions

outlining the operation of an

algorithm written so that a

human can understand them.

• Good pseudo code design must:

– Have line numbers

– Have clear descriptions without

being too complex

– Be indented to show similar

blocks of code

– List actions as capital letters.

Page 18: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

What next?

• Look at algorithm designs that use sequence,

selection and iteration

• Produce code from these designs using

Python

Page 19: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Hints

• Never use the P – word – “coding” is better

• “Code cards” are good for teaching syntax

• Give students example code / code to alter?

• Look at “algorithms” using pseudo code /

flowcharts then produce code using Python

• They are children!

Page 20: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Is Python working?

1. Open up IDLE, (basic Python programming

environment)

2. Type these commands into the interactive shell

(answering where necessary)

Page 21: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Overview

Housekeeping

Introduction

Session 1

Session 2

Plenary

Session 3

Homework

Webinar

Questions

Feedback

• “The beginning is the most important part of the work.” Plato

Session 2: From algorithms to Python code

Page 22: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Describing the simple start

• If simple programs are easy to code why

bother with design?

Size of problem

Effort Hacker’s curve

Size of problem

Effort

Designer’s line

Page 23: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Flowcharts

• If simple programs are easy to code why bother with design?

Start End

Input Output

Process

Used to define the start and end points of the algorithm

Input – what the user enters into the program Output – what is produced by the computer, (on screen, printed, etc.)

Used to explain anything the computer needs to work out, (eg 2 + 2)

Decision

Used to create different paths

through the algorithm

Page 24: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Algorithms that use sequences

• Consider the program we made as a flowchart:

Start

OUTPUT “What is

your name?"

INPUT name

OUTPUT “Hello” +

name

End

Overkill when you know what you are doing but may help pupils visualise what is happening.

Page 25: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Equivalent pseudocode

• A detailed flowchart allows you to create quick pseudocode:

Start

OUTPUT “What is

your name?"

INPUT name

OUTPUT “Hello” +

name

End

1. START 2. OUTPUT “What is your name?” 3. INPUT name 4. OUTPUT “Hello” + name 5. END

Page 26: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Python parts

• Python programs can be constructed quickly and

executed through IDLE, (Interactive DeveLopment

Environment)

Single command typed and executed through the interactive shell

Page 27: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Text editor

• Programs are usually more than one line so use the

file editor to write your programs, (when executed

(F5) the output appears in the interactive shell)

Page 28: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Text editor

• When writing a program it is good practice to

describe parts that aren’t obvious, (using comments)

Page 29: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Python Data Types

Data Type Python Data Type

Example

Integer int() 5

Real float() 5.5

String str() 'Hello'

Boolean bool() True

Page 30: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Python Operators

Operator Python Code Answer

Addition Subtraction

Multiplication Division

3+5 5-1 3*3 5/2

8 4 9

2.5

Exponent (repeated multiplication)

2**3 8

Modulo (remainder after division)

12%5 2

Equal Not Equal

10==9 'Jaz'!=’Fred'

False True

Greater than Less than

'z'>'a' 5<3

True False

Page 31: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

+ Assignment, Input and Output in Python

• Some languages require that variables be declared (and data type specified) before they are used to store values. Python does not require the declaration of variables before use.

• For example the code required to create a variable named count of data type integer storing (assigning) the value 5 is: count = 5

• If you wanted to store this as a real/float: count = 5.0

Page 32: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

+ Assignment, Input and Output in Python

• Python makes it easy to convert valid data between types.

• A valid string can be converted into real/float, integer or boolean: float('3.5') int('55') bool('True')

• A real/float can be converted into an integer (it will be rounded down): int(3.8)

• An integer can be converted into a real/float: float(6)

Page 33: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Your turn

Now try making some sequential

programs using Python.

Page 34: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Your turn

# A program for greeting people

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

print ("Hello, " + name + "! How are you?")

print ("My name is" , name)

1) Copy this into IDLE, and Save the file into your Python Folder with the

name "greeting.py". Press F5 to run.

2) Write a program that asks two people for their names; stores the names in

variables called name1 and name2; says hello to both of them.

Page 35: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Your turn

# Numbers code

a = 3

b = 5

c = 7

print ("These are the values:", a, b, c)

print ("Increment", a, "by one: ")

a = a +1

print (a)

print ("The sum of", a, "and", b, "is")

d = a + b

print (d)

number = int(input("Input a number "))

print ("Number is ", number)

number2 = number * 2

print ("Number times two is", number2)

Copy this into IDLE, and Save the file into your Python Folder with the name

"numbers.py". Press F5 to run.

Page 36: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Execute this algorithm!

Drink coffee

Has 5 minutes elapsed?

Start session 2

Eat biscuits

Page 37: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Algorithms that use conditions

• Programs rarely run in order, needing to

respond to events and change the order

they run in

• This involves conditional constructs, (parts of

the coding language we can use)

Page 38: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

IF statements

• Check is a condition is TRUE and execute a related statement:

IF condition is true THEN execute this statement END IF

IF score > 50 THEN OUTPUT “You passed!” END IF

Is score > 50?

Output “You

passed!”

Yes

No

Page 39: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

IF…ELSE statements

• ELSE can be added to IF to offer an alternative if the first condition isn’t met:

IF condition is true THEN execute this statement ELSE execute this statement END IF

IF score > 50 THEN OUTPUT “You passed!” ELSE OUTPUT “You failed!” END IF

Is score > 50?

Output “You

passed!”

Yes

No

Output “You

failed!”

Page 40: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

ELSE IF statements

• Can add as many tests that you want:

IF condition is true THEN execute this statement ELSE IF condition is true THEN execute this statement ELSE execute this statement END IF

IF score > 50 THEN OUTPUT “You passed!” ELSE IF score > 0 THEN OUTPUT “You failed!” ELSE OUTPUT “Zero scored!” END IF

Is score > 50?

Output “You

passed!”

Yes

No

Is score > 0?

Output “You

failed!”

Yes

Output “Zero

scored!”

No

Page 41: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Using conditional constructs in Python

• Python works on white space and indents to separate IF statements into blocks:

Page 42: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Nesting IFs

• The advantage of the block method is that the programmer has to think about making the code easy to read:

Page 43: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

A very important point!

• Indentation is key! It determines where the start and end is of different blocks of code.

• SyntaxError: unexpected indent indicates a problem with your indentation.

• And don’t forget colons in IF / WHILE statements

Page 44: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Your turn

Now try making some conditional

programs using Python.

Page 45: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Your turn

# works out whether a number is positive,

# negative or zero

num = int(input("Enter a whole number: "))

if num < 0:

print("The number is negative")

elif num > 0:

print("The number is positive")

else:

print("The number is zero")

Copy this into IDLE, and Save the file into your Python Folder with the name "numchecker.py". Press F5 to run

Page 46: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Your turn

1) Write code from this flowchart 2) Write code that asks for the user’s age to be typed in at the keyboard, then displays a message that states whether or not the user is old enough to drive. 3) Write code that asks for two numbers to be typed in at the keyboard, then display the larger of the two numbers.

Page 47: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Overview

Housekeeping

Introduction

Session 1

Session 2

Plenary

Session 3

Homework

Webinar

Questions

Feedback

• Plan algorithms using flowcharts

and pseudocode

• Implement simple algorithms using Python

• Understand and use some basic

programming constructs used to control the

flow of a program

Plenary

Page 48: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Interactive websites for learning Python

• Computer Science Circles – University of Waterloo, Canada http://cscircles.cemc.uwaterloo.ca/

• How to think like a Computer Scientist - Interactive Edition http://interactivepython.org/courselib/static/thinkcspy/index.html

• Problem solving with Algorithms and Data Structures using Python http://interactivepython.org/courselib/static/pythonds/index.html

• Pygame – a set of Python modules designed for writing games. http://www.pygame.org/news.html

Page 49: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

…final thoughts from Session 1

a) Download Python 3.x (latest version)

b) Interactive websites for using Python

c) Also recommend you check out

http://www.codecademy.com/tracks/python

d) There's some cool stuff on Python here on Khan Academy http://www.khanacademy.org/science/computer-science

e) How to Think Like a Computer Scientist is pretty good too, at http://interactivepython.org/courselib/static/thinkcspy/index.html#learning-with-python-interactive-edition-using-python-3-x

f) Especially go and look at the stuff on FOR loops and WHILE loops on

Khan Academy

Page 50: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

…and relax!

LUNCH

Page 51: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Overview

Housekeeping

Introduction

Session 1

Session 2

Plenary

Session 3

Homework

Webinar

Questions

Feedback

• “Over and over and over and over and over; Like a monkey with a miniature cymbal” Hot Chip – Over and over

Session 2: Iterative programs

Page 52: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Algorithms that use iteration

• Programs often repeat themselves

• A loop can be programmed to run a given

number (count-controlled)

• Or a loop can continue until a certain finishing

state has been achieved (condition-controlled)

Page 53: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Loop comparison for plate of 3 biscuits

Eat biscuit

For biscuit 1 to 3

Next biscuit

Start on sandwiches

Eat biscuit

Are there biscuits on plate?

Next biscuit

Start on sandwiches

Page 54: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Count-controlled loops

• A loop that runs a specific number of times:

FOR var=start num TO end num execute this statement END FOR

FOR i = 1 TO 10 OUTPUT i END FOR

Is i <= 10?

Output i

Yes

No

i = i + 1

i = 1

Page 55: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Python FOR construct

• Again Python uses white space and indents to separate FOR statements into blocks:

Page 56: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Python FOR construct

• Note that Python needs to be told what to count to and how to count:

FOR i = 1 TO 10 OUTPUT i END FOR

for i in range(1,11): print(i)

FOR i = 10 TO 1 OUTPUT i END FOR

for i in range(10,0,-1): print(i)

Page 57: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Condition-controlled loops - WHILE

• Loop that runs until condition is met, (and may never run):

WHILE condition is true execute this statement END WHILE

WHILE x < 10 OUTPUT x x = x + 1 END WHILE

Is x < 10?

Output x

Yes

No

x = x + 1

Page 58: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Condition-controlled loops - REPEAT

• Loop that will run at least once:

REPEAT execute this statement UNTIL condition is true

REPEAT OUTPUT x x = x - 1 UNTIL x <= 0

Is x <= 0?

Output x

No

x = x - 1

Page 59: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Python WHILE construct

• Python uses white space and indents to separate WHILE statements into blocks:

Page 60: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Python REPEAT construct

• Python doesn’t have a specific REPEAT construct so we have to adapt a WHILE loop:

Page 61: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Your turn

Now try making some simple

iterative programs using Python.

Page 62: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Your turn

1) Use a While Loop to write code for this flowchart

2) Times tables Use a For loop to write Python code to print a multiplication table (a times table). At the start it should as the user which number they want to see the times table for by asking “Which times table would you like?”

Hints: you will need to use 2 variables and one of these will be the user input (the times table wanted). Example output: Which times table would you like? 5 Here’s your table: 5 x 1 = 5……..

Page 63: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Try this.....

What does this do? import random n = random.randint(1,100) print (n) 1) Dice Rolling

Write a program that simulates (acts like) rolling a die. The program should ask the user if they want to roll the dice, while they say yes it should tell them the number they have rolled (“You have rolled a “). It should ask them again after each roll. If they say no, the program should say ‘Goodbye’

2) Guess the number game.

Create a game where the computer generates a random integer between 1 and 100 and the player has to try and guess it in as few attempts as possible. Each time the player enters a guess the computer tells the player whether the guess is too high, too low or correct! Once the player guesses the number the game is over.

Page 64: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

“It’s no good joyfully writing a curriculum if no

one can teach it”

Adrian Mee, IoE, University of London

Page 65: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

I have a piece of paper that is more intelligent than anyone

in this room …

Maybe things we don’t have time for...

Page 66: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Playing Noughts & Crosses Perfectly

Move 1: Go in a corner.

Move 2: If the other player did not go there then go in the opposite corner to move 1.

Otherwise go in a free corner.

Move 3: If there are 2 Xs and a space in a line (in any order) then go in the space.

Otherwise if there are 2 Os and a space in a line then go in that space.

Otherwise go in a free corner.

Move 4: If there are 2 Xs and a space in a line (in any order) then go in the space.

Otherwise if there are 2 Os and a space in a line then go in that space.

Otherwise go in a free corner.

Move 5: Go in the free space.

Page 67: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Explaining algorithms

• Having played OXO you are in a position to: – Explain what an algorithm is

– What a program is

– Have a discussion of whether computers are intelligent if they are just following rules and even the philosophy of mind!

• Students can try to write a similar perfect set of instructions for playing second

• Programming without letting language syntax get in the way!

Page 68: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Other good algorithms

• Making sandwiches

• Changing tyres

• Painting finger nails

• Tying shoe laces

• Playing Black Jack

Page 69: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Other teaching ideas....

• Step away from the computer

• Students organise “code cards” into the correct order (hopefully!) - useful for teaching syntax and for asking “what changes if” type questions..

Page 70: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

A LOGO class activity, works well in other languages too..

NB LOGO is highly recommended, esp at KS3. It is a powerful, Lisp-like language that was explicitly designed to be easy for students to learn. It can be used to

teach most computer science concepts!

Page 71: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

A card activity introducing Assembly Language coding.....

Page 72: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Scratch “Jigsaws”

Page 73: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Files to edit / add to... NOT code that is wrong that

they need to correct...

Page 74: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Homework.....

Blackjack

• Set up variables for the player score, the dealer score • Deal two cards to each (use a random number) • Make a variable called end_the_game and set it equal to False • Make a loop that only runs while end_the_game is False (i.e. the game has not ended)

• Inside the loop, get input from the player to ask what he wants to do

• If his input was “stick” • print out his total and the dealer’s total • check who has won and print it • end the game

• If his input was “hit”: • draw him a new card and add it to his total • check if he has bust

• if so the game ends and he loses, if not print his new total • if he didn’t bust,

• if the dealer draws (only when he is on <17) • Give him a new card

• if the dealer is bust • the game ends and the player wins

Page 75: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Overview

Housekeeping

Introduction

Session 1

Session 2

Plenary

Session 3

Homework

Webinar

Questions

Feedback

Homework #2

Page 76: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Overview

Housekeeping

Introduction

Session 1

Session 2

Plenary

Session 3

Homework

Webinar

Questions

Feedback

Homework #3 – A453 Specimen Task

It would be excellent practice to complete this task. In order to complete it, you will need to independently investigate “lists “ and “string handling”. Design, code test and evaluate a system to accept and test a password for certain characteristics. It should be at least 6, and no more than 12 characters long • The system must indicate that the password has failed and why, asking the user to re • enter their choice until a successful password is entered. • A message to indicate that the password is acceptable must be displayed. • Password strength can be assessed against simple criteria to assess its suitability; for • example a password system using only upper and lower case alphabetical characters

and numeric characters could assess the password strength as: • WEAK if only one type used, eg all lower case or all numeric • MEDIUM if two types are used • STRONG if all three types are used.

For example hilltop, 123471324, HAHGFD are all WEAK, catman3 and 123456t are MEDIUM and RTH34gd is STRONG A message to indicate the password strength should be displayed after an acceptable password is chosen.

Page 77: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

Overview

Housekeeping

Introduction

Session 1

Session 2

Plenary

Session 3

Homework

Webinar

Questions

Feedback

• Plan algorithms using flowcharts

and pseudocode

• Implement algorithms using Python

• Understand and use the three basic

programming constructs used to

control the flow of a program

Plenary

Page 78: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

More stuff.....

• That we probably haven’t had time to cover... for GCSE you also need to know about “lists” and “file handling”

• Running a session on all this at Pate’s next week where we will also go through the A453 practical tasks – there will be another session in the Autumn term

Page 79: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

More stuff....

• All the resources from this session I will make available on CAS Online and link to from the symposium website

Page 80: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

If you do ONE thing do this ... pythonschool.net

Page 81: John Palmer - Worc Inputs/CAS... · •Plan simple algorithms using flowcharts ... use different types of data including Boolean, ... Equivalent pseudocode

@johnny__palmer

Questions Comments

Observations

Etc....