programming in python lesson 2. starter activity complete the starter activity

20
programming in python Lesson 2

Upload: margaretmargaret-brown

Post on 16-Dec-2015

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Programming in python Lesson 2. Starter Activity Complete the starter activity

programming in python

Lesson 2

Page 2: Programming in python Lesson 2. Starter Activity Complete the starter activity

Starter Activity

Complete the starter activity

Page 3: Programming in python Lesson 2. Starter Activity Complete the starter activity

Recap Starter• Recap starter

• What is wrong with it?•

• • print(“hello)• number = 17• number• 17• print(“Your number is”,number)• PRint(“bye”)

print(“hello”)

print(“bye”)

Page 4: Programming in python Lesson 2. Starter Activity Complete the starter activity

Lesson Outcomes

• All-Level 4- Know the key data types discussed in lesson• With help be able to write a variable with help• To be able to store a user inputted variable with help• Understand and demonstrate the basic data types

• Most-Level 5- Be able to write a these with little help. • Some-Level 6- independently write these and adapt

them

Page 5: Programming in python Lesson 2. Starter Activity Complete the starter activity

Recap

• Lets recap what we learnt last lesson• What is a program? • A program is a sequence of instructions that

specifies how to perform a computation. • What is syntax?• Refers to the spelling and grammar of a

programming language

Page 6: Programming in python Lesson 2. Starter Activity Complete the starter activity

Variables

• One of the most powerful features of a programming language is the ability to manipulate variables.

• A variable is a name that refers to a value.• The assignment statement creates new

variables and gives them values:

• >>> message = "What's up, Doc?“• >>> n = 17

Page 7: Programming in python Lesson 2. Starter Activity Complete the starter activity

Variables

>>> N = 17>>> N>>> 17

Assignment/Input

Variable

Result/Output

Page 8: Programming in python Lesson 2. Starter Activity Complete the starter activity

Task 1

• Using variables to demonstrate basic math code. + - / *• E.g. • Number 1 + number 1

»Variables»If you are stuck you can download the

Help program

Page 9: Programming in python Lesson 2. Starter Activity Complete the starter activity

Task 2

• Have a look at this line of code

• print(“Your number is”,number)• number is a variable • The comma separates the text and the variable• Your task is to write a code that prints a name

and displays it. Have a look at the starter task to help you.

Page 10: Programming in python Lesson 2. Starter Activity Complete the starter activity

input

• Now we know what a variable is we can use the input statement to store things.

• >>> print(“what is your name”)• >>>name = input()• >>>print(name)

• Copy this on the board• Adapt this code to something of your choosing e.g. a

user inputs their details then you display them

Page 11: Programming in python Lesson 2. Starter Activity Complete the starter activity

Data types

• Integer • Float• String • Boolean

• There are mean other numbers but we will stick to these main ones

Page 12: Programming in python Lesson 2. Starter Activity Complete the starter activity

Data Types

• Examples of strings are: 'Hello', "Goodbye". To input a string, use input()

• Examples of integers are: 2, 6, -89, 45421. To input an integer at the screen, use int(input())

• Examples of floats are: 2.4, 6.0, -89.54, 111.111. To input a float number at the screen, use float(input())

• A boolean variable always has the value True or False. Remember Python is case sensitive so the capital 'T' and 'F' really matters!

Page 13: Programming in python Lesson 2. Starter Activity Complete the starter activity

Data types What is a string? Examples of strings are: 'Hello', "Goodbye". How do you enter it?Input()What is a integerare: 2, 6, -89, 45421.How do you enter it?int(input()) What is a float numberHow do you enter it?float(input()) What is a boolean?has the value True or False.Variableboolean = True

Page 14: Programming in python Lesson 2. Starter Activity Complete the starter activity

Task 4

• Have a go at entering these values and displaying them• strings are: 'Hello', "Goodbye".

To input a string, use input() • integers are: 2, 6, -89, 45421.

To input an integer at the screen, use int(input()) • 2.4, 6.0, -89.54, 111.111.

To input a float number at the screen, use float(input()) • A boolean variable always has the value True or False.

Remember Python is case sensitive so the capital 'T' and 'F' really matters!

Page 15: Programming in python Lesson 2. Starter Activity Complete the starter activity

Task 3

• Your code should look something like this

Page 16: Programming in python Lesson 2. Starter Activity Complete the starter activity

Self Evaluation Task

• Open the Self Evaluation Task.

• Have a look at the outcomes of the lesson. • Write down the level you think you got this

lesson• Self evaluate your progress this lesson and

write your Level and your Student Next Step.

Page 17: Programming in python Lesson 2. Starter Activity Complete the starter activity

Plenary

• Now we know what a variable is we can use the input statement to store things.

• >>> print(“what is your name”)• >>>name = _________• >>>print(name)

input()

Page 18: Programming in python Lesson 2. Starter Activity Complete the starter activity

Plenary

• Integer • _______• String • _______

• There are mean other numbers but we will stick to these main ones

Float

Boolean

Page 19: Programming in python Lesson 2. Starter Activity Complete the starter activity

Plenary• What is a string? • Examples of strings are:• How do you enter it?• Input()• What is a integer• are: • How do you enter it?• int(input()) • What is a float number• How do you enter it?

• What is a boolean?• has the value True or False.• Variableboolean = True

'Hello', "Goodbye".

2, 6, -89, 45421.

float(input())

Page 20: Programming in python Lesson 2. Starter Activity Complete the starter activity

Acknowledgments

• Some resources and lessons were taken from

http://www.pythonsummerschool.net/