type accurately challenge! this is a starter activity and should take 2 minutes [ slide 1 ] 1.can...

8
Type accurately challenge! This is a starter activity and should take 2 minutes [ slide 1 ] 1.Can you type out the code in Code Box 2.1 with no errors – first time? 2. Can you work out what \n does?

Upload: magdalen-dorsey

Post on 03-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Type accurately challenge!This is a starter activity and should take 2 minutes

[ slide 1 ]

1. Can you type out the code in Code Box 2.1 with no errors – first time?

2. Can you work out what \n does?

Lesson Aims

1. Learn how to do more with text

2. Get Python to do some maths for you

3. Learn how to combine maths and text

[ slide 2 ]

Vocabularyescape sequence

string

integer

float

function

mathematical operator

modulus

interactive mode

In this lesson you are going to:

Programming Session Rules

1. Try to complete the task set on your own computer

2. If you have finished and are waiting, you may:

• try out your own code

• help other students who are stuck.

3. When asked to stop:

• go back to your seat

• stop coding

• listen carefully.

[ slide 3 ]

Escape sequences:[ slide 4 ]

You have been using IDLE in interactive mode. This is when we write a command and it is run as soon as we press ENTER on the keyboard.

Interactive mode is great for experimenting.

1. Read page 17 and 18 in the textbook.

2. Using a copy your code from Code Box 2.1, change the escape sequence to some of those below to see what they do.

3. Try running the code from Code Box 2.2 and 2.3 (on page 18)

Maths in Python

[ slide 5 ]

1. Read the Maths section on page 19 and 20

2. Race a friend with a calculator to see whether Python is faster than a calculator:

a) 5 * 6.5 =

b) 7 / 3 =

c) 128 + 6 =

d) How many times does 120 divide by 7?

e) What is the remainder of 120 / 7?

Functions (more in chapter 4)[ slide 6 ]

print() is a function.

We can put a variety of things inside the brackets to be printed to the screen .So far we have supplied bits of text but it can do much more ...Coders call text, strings.

Output from the print function appears in blue text.

Combining Maths and Text

[ slide 7 ]

The print() function will print to screen:

strings, numbers or calculations separated by commas:

Interactive session:>>> print("111 divided by 4 = ", 111/4)

111 divided by 4 = 27.75

>>> print("11 divided by 4 = ", 11/4)

11 divided by 4 = 2.75

What will the output from this code produce?

>>> print("11 divided by 4 = ", 11//4, "remainder ", 11%4)

11 divided by 4 = 2 remainder 3>>> print("I will not write code in history lessons.\n" *50)

See what else you can produce.

Can you fill the screen with your name?

Now try entering this code:

Lesson Summary

In coding, snippets of text are called ...

[ slide 8 ]

In this lesson you have:

stringsWhole numbers are called ... integers

Numbers with a decimal point are called ...floating point numbers (or floats)

To use special Python characters we need ...escape sequences

In Python, the remainder of a division is called ...modulus

1. Learnt how to do more with text

2. Got Python to do some maths for you

3. Learnt how to combine maths and text