Transcript strings
[ slide 1 ]
Type accurately challenge!
This is a starter activity and should take 2 minutes
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?
[ slide 2 ]
Lesson Aims
In this lesson you are going to:
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
Vocabulary
escape sequence
function
string
mathematical operator
integer
modulus
float
interactive mode
[ slide 3 ]
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.
Escape sequences:
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)
[ slide 4 ]
[ slide 5 ]
Maths in Python
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?
[ slide 6 ]
Functions (more in chapter 4)
Output from the print function appears in blue text.
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.
[ slide 7 ]
Combining Maths and Text
The print() function will print to screen:
strings, numbers or calculations separated by commas:
Interactive session:
>>> print("111 divided by 4 = ", 111/4)
What
willentering
the output
this code produce?
Now try
thisfrom
code:
111 print("11
divided bydivided
4 = 27.75
>>>
by 4 = ", 11//4, "remainder ", 11%4)
>>>
print("I
will
not write
code
in history lessons.\n" *50)
>>>
print("11
divided
by
4
=
",
11/4)
11 divided by 4 = 2 remainder 3
11 divided
by 4
2.75
See
what else you
can= produce.
Can you fill the screen with your name?
[ slide 8 ]
Lesson Summary
In this lesson you have:
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
In coding, snippets of text are called ...
strings
integers
Whole numbers are called ...
Numbers with a decimal point are called ...
floating point numbers (or floats)
To use special Python characters we need ...
In Python, the remainder of a division is called ...
escape sequences
modulus