Teaching London Computing

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
Advertisements

Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Recitation 1 Programming for Engineers in Python.
An Introduction to Textual Programming
Introduction to Python
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Do it now activity Last term we learnt about how data is represented in a computer and about how to identify different volumes of data. How many bits in.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
ECS 15 Variables. Outline  Using IDLE  Building blocks of programs: Text Numbers Variables!  Writing a program  Running the program.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 17, 2015)
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
COMPUTER PROGRAMMING Year 9 – Unit 9.04 Week 3. Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
Introduction to Programming
Introducing Python Introduction to Python.
Introduction to Programming
Whatcha doin'? Aims: To start using Python. To understand loops.
A Playful Introduction to Programming by Jason R. Briggs
Python Let’s get started!.
Introduction to Python
Introduction to Python
Advanced Coding Session 5
Introduction to Programming
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Variables, Expressions, and IO
Little work is accurate
Lesson 1 Learning Objectives
Week 3 Computer Programming Learning Objective:
Learning to Program in Python
Teaching London Computing
Introduction to Programming
Fill the screen challenge!
Week 1 Computer Programming Year 9 – Unit 9.04
You think you can just do your sums in any order you like. THINK AGAIN
Learning Outcomes –Lesson 4
T. Jumana Abu Shmais – AOU - Riyadh
Task 1 Computer Programming LEVEL 6 PROGRAMMING:
Introduction to TouchDevelop
Margaret Derrington KCL Easter 2014
Introduction to Programming
A look at Python Programming Language 2018.
Beginning Python Programming
Introduction to Programming
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Learning Intention I will learn about the different types of programming errors.
Input and Output Python3 Beginner #3.
Introduction to Python
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
More Strings.
Starter Activities GCSE Python.
Hardware is… Software is…
Presentation transcript:

Teaching London Computing 1.1 Numbers and Strings Margaret Derrington KCL Easter 2014

Remember the two PYTHON windows The shell Where the program runs The IDLE Where you write and edit a program You can also OPEN an existing program From ANY FILE menu It will open in its own IDLE window where you can edit it and click RUN And it will run in the shell window. If you close the SHELL, it will open when you RUN something If you close the IDLE you can open a new one from the SHELL If you close them both, you will have to open Python all over again

The Shell The shell is a bit like a calculator If you write a line of code in there Next to the prompt >>> When you click RETURN/ENTER/SEND It will run and print… there, where it is, in the shell But you cannot write programs here Because every time you click ENTER It runs what you have just typed But one line scripts will run here… So it is useful for testing and checking things If you are writing a complicated program in the IDLE, you can check or test bits of it as you go.

So let’s test some stuff in the shell Type a string in the shell “Hello World” And it will print it back to you Type a sum 3*85 or 3.8745 - 2.999 It will give you the answers… So, what happens if you add a string to a number? What happens if you multiply a string by a number? What happens if you add two strings? Or three? Interesting? It’s called concatenation

ARITHMETIC Insert numbers for x and y and work out what these OPERATORS do: x + y x – y x * y x ** y x / y x // y -x +y pow(x,y) You can test them all in the python shell…… ……………………..they are one-liners!!! Check what happens with 10 – 5 – 2 10 – (5-2) TWO kinds of division 10/4 10//4 Well THREE actually 10%4 And 2 * 3 + 5 how does this compare with a calculator?

Indexing and slicing strings INDEXING returns a numbered character "william"[0] – gives ‘w’ "william"[1] – gives ‘i’ "william"[6] – gives ‘m’ and “william”.index(“i”) gives 1 …the index or position of the first i SLICING gives a range "william"[1:4]– gives ‘ill’ The numbering starts with ZERO!!!!! (not all languages do this, but many do) INcluding character number 1 EXcluding character number 4

String Length len() is a function that returns the LENGTH of a string; the number of characters len(“hello world”) gives 10 (including the space) How would you make python return “world? Use slicing and THINK about the numbers You should be able to do this in FOUR different ways!!!!!! Hint:: use len and index

String Length len() is a function that returns the LENGTH of a string; the number of characters len(“hello world”) gives 10 (including the space) How would you make python return “world? Use slicing and THINK about the numbers “hello world” [6:10] Or “hello world” [6:len(“hello world”)] Or “hello world” [“hello world”.index(“ ”):10] or “hello world” [“hello world”.index(“ ”): 6:len(“hello world”)]

Errors Python has fewer errors than other languages (e.g. Java) This has both pros and cons Not everything we write makes sense Syntax error: 123abc 1 ! 3 “hello “I can’t understand what you are asking” Wassup??? Wosswrong????

Errors Python has fewer errors than other languages (e.g. Java) This has both pros and cons Not everything we write makes sense Syntax error: 123abc – not a number 1 ! 3 – not an operator “hello – a string with no end “I can’t understand what you are asking”

Why do these not make sense??? Evaluation Errors “The text looks ok but when I try to calculate, it makes no sense” 42 + “hello” 42 / 0 “hello”[17] Why do these not make sense??? What’s wrong?

Evaluation Errors “The text looks ok but when I try to calculate, it makes no sense” 42 + “hello” – can’t add a number to a string 42 / 0 – can’t divide by zero “hello”[17] – can’t index beyond the end “hello”[5] - is this correct ?????

We have speeded up and learnt a LOT more!!! IDLE, SHELL, open save run ARITHMETIC including some new operators ** // and % and a function pow (n,m) Strings: indexing, slicing, concatenating, the function len() and the method “string”.index() And a little bit about errors. We have been doing these in the shell Next we are going to use what we have learnt to write some PROGRAMS…… where?

Back in the IDLE window Write a program that will print your name print the number of letters in your name Slice your name and print it letter by letter each on a different line Add the number on letters in your first name to the number in your second name and print the answer. Save your program in your named file in my documents… call it something suitable. THINK…. Are you going to do this all at once or are you going to try it out bit by bit, adding each next bit when you have got the rest to work? ……… just wondered…. 