GCSE Python Programming 1 - Introduction

s1perry
9 Sept 201824:50

Summary

TLDRThis video lecture series introduces Python programming, tailored for GCSE students. It explains the basics of programming languages, emphasizing Python's simplicity and readability. The series covers key programming concepts like syntax, sequencing, selection, and iteration, and demonstrates Python's popularity and practical applications. Viewers are guided through setting up Python's IDE, writing simple programs, and understanding common errors. The lecture encourages experimentation and learning from mistakes, offering interactive examples and extension exercises to deepen comprehension.

Takeaways

  • πŸ˜€ Programming languages are sets of vocabulary and grammatical rules that instruct computers to perform tasks.
  • πŸ” High-level languages like Python are more human-readable and are compiled into machine code that computers execute.
  • 🌐 Python is a versatile, high-level programming language known for its simplicity and readability, making it ideal for beginners and experienced programmers alike.
  • πŸ“ˆ Python's popularity has been increasing, as evidenced by web searches and its prevalence on platforms like Stack Overflow.
  • πŸ’» An Integrated Development Environment (IDE) like IDLE, which comes with Python, facilitates easier programming with features like color coding and a shell mode.
  • πŸ›  Basic programming concepts include sequencing, selection, and iteration, which are fundamental to all programming languages.
  • πŸ”’ Python emphasizes code readability and allows for expressing complex ideas in fewer lines of code compared to other languages like C.
  • πŸ“ Syntax is crucial in programming; even minor mistakes can lead to errors, which are common even among experienced programmers.
  • πŸ”‘ Keywords in Python, like 'print', are special words that the language understands and are highlighted in the IDE to help identify errors.
  • πŸ“š Learning to spot and correct syntax errors is an essential skill for programmers, and IDEs like IDLE provide tools to assist with this.
  • πŸŽ“ The script encourages experimentation and learning through trial and error, emphasizing the importance of practice in programming.

Q & A

  • What is the main focus of the video series?

    -The main focus of the video series is to teach Python programming, specifically tailored for those studying the GCSE exam syllabus.

  • Why is Python used in this series instead of other programming languages?

    -Python is used because of its simplicity, readability, and the fact that it allows programmers to express complex concepts in fewer lines of code compared to languages like C.

  • What is a programming language in the context of this script?

    -A programming language is a vocabulary and set of grammatical rules for instructing a computer to perform specific tasks.

  • How does the script describe the evolution of programming languages?

    -The script describes the evolution from early computers performing basic mathematical operations to the development of high-level and low-level programming languages that can be easily converted into machine code.

  • What is the significance of decomposition in programming as mentioned in the script?

    -Decomposition is the process of breaking down a large complex task into smaller subtasks, which are easier to solve and can be combined to solve the larger problem.

  • What are the three key programming concepts that every programming language involves?

    -The three key programming concepts are sequencing (putting instructions in order), selection (making choices based on conditions), and iteration (repeating tasks multiple times).

  • Why is Python considered a beginner-friendly language according to the script?

    -Python is considered beginner-friendly due to its simple syntax, readability, and the fact that it allows for clear programming constructs on both small and large scales.

  • What is the role of an IDE in programming with Python?

    -An IDE (Integrated Development Environment) like IDLE, which comes with Python, provides a user-friendly interface and tools to make programming more pleasant and simpler.

  • How does the script illustrate the concept of input and output in Python?

    -The script uses the 'input' function to gather information from the user and the 'print' function to display output, demonstrating basic interaction within a Python program.

  • What is a syntax error and why are they common in programming?

    -A syntax error occurs when the code does not follow the correct grammatical structure that the programming language understands. They are common because even small mistakes can cause the program not to run, and computers require exact instructions.

  • How does the script suggest handling syntax errors in Python?

    -The script suggests checking the code carefully for common mistakes like incorrect brackets, missing speech marks, or incorrect keyword spelling. It also mentions using color coding in the IDE to spot potential errors.

  • What are some additional Python programs suggested in the script for further practice?

    -The script suggests creating programs to calculate the area of a triangle using the formula, and another to calculate how many days a user has been alive based on their age.

Outlines

00:00

🐍 Introduction to Python Programming

This paragraph introduces the series on Python programming aimed at GCSE students. It explains the concept of programming languages, their purpose, and the specific use of Python for this series. The speaker emphasizes the importance of understanding syntax and programming constructs like sequencing, selection, and iteration. The paragraph also touches on the history of programming and the evolution of computer languages, highlighting Python's simplicity and readability as advantages for beginners.

05:03

πŸ“ˆ Python's Popularity and IDEs

The speaker discusses the popularity of Python, citing data from The Economist and Stack Overflow, showing Python's rise in web searches and its status as the most popular language on Stack Overflow. The paragraph also introduces the concept of an Integrated Development Environment (IDE), specifically Python's IDLE, which is the default IDE that comes with Python. The speaker guides the audience on how to use IDLE, configure it for writing full programs, and the importance of experimenting with code.

10:06

πŸ‘‹ Writing a Simple 'Hello World' Program

The paragraph demonstrates how to write a basic 'Hello World' program in Python using IDLE. It explains the process of opening a new window, typing the program, saving it, and running it. The speaker also discusses the importance of syntax, such as using the correct keywords, brackets, and quotation marks. The paragraph encourages learners to experiment by changing the text and adding more print statements to see how the program behaves.

15:10

πŸ”„ Interactive Python Programs and Syntax Errors

This section introduces the concept of interactive Python programs with the 'input' function, allowing users to enter data that the program can use. The speaker provides an example where the user's name is inputted and then printed out in a greeting. The paragraph also delves into syntax errors, explaining how even small mistakes can cause programs to fail and emphasizing the importance of careful typing and debugging.

20:11

πŸ›  Handling Syntax Errors and Writing More Complex Programs

The speaker provides guidance on how to identify and correct syntax errors, using color coding in IDLE as a tool. They also explain the importance of case sensitivity in programming. The paragraph includes an example of a more complex program that calculates the remaining calories a person can eat in a day, introducing the 'int' function to convert input into an integer for mathematical operations. The speaker encourages learners to try the program, make modifications, and understand the process of debugging.

πŸ“š Extending Knowledge with Additional Python Programs

In the final paragraph, the speaker suggests extension programs for practice, such as calculating the area of a triangle and determining how many days a person has been alive. These exercises aim to deepen the understanding of Python programming by incorporating user input, mathematical operations, and print statements. The speaker reassures learners that it's normal to struggle with some concepts and encourages them to keep practicing and experimenting with Python.

Mindmap

Keywords

πŸ’‘Programming Language

A programming language is a formal language comprising a vocabulary and set of grammatical rules that allow us to instruct a computer to perform specific tasks. In the video, it is the central theme as the instructor explains that programming languages act as a bridge between human-understandable instructions and the binary code (ones and zeros) that computers execute. Examples include Python, C, C++, and JavaScript, with Python being the focus of the video due to its readability and ease of use for beginners.

πŸ’‘Python

Python is a high-level, general-purpose programming language that is known for its simplicity and readability. The video emphasizes Python's design philosophy which prioritizes code readability and its syntax that allows for expressing complex ideas concisely. It is used as the teaching language in the video because of its popularity and suitability for beginners, as well as its wide range of applications from web development to scripting.

πŸ’‘Syntax

Syntax in programming refers to the set of rules that dictate how instructions, statements, and expressions are formed in a language. The video explains the importance of syntax in programming with Python, noting that correct syntax is crucial for the computer to understand and execute the code. Examples from the script include the proper use of keywords, brackets, and quotation marks.

πŸ’‘IDE (Integrated Development Environment)

An Integrated Development Environment, or IDE, is a software application that provides comprehensive facilities for coding, debugging, and running programs. In the video, the instructor introduces IDLE, which is Python's standard IDE, as a tool to make programming more user-friendly by providing a space to write, save, and run Python programs.

πŸ’‘Variables

A variable in programming is a storage location paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value. The video introduces the concept of variables with the example of storing user input in a variable named 'name' and later using it in a print statement.

πŸ’‘Input and Output

Input and output are fundamental concepts in programming where 'input' refers to the way data is entered into a program, and 'output' is how the results of computations are displayed or utilized. The video demonstrates input with the 'input()' function in Python, which allows the program to receive data from the user, and output with the 'print' statement, which displays data on the screen.

πŸ’‘Conditional Execution

Conditional execution is the concept of making decisions within a program based on certain conditions. The video touches on this concept by explaining that programs can execute different blocks of code depending on whether certain conditions are met, such as checking if a password is correct or if a user is above a certain age.

πŸ’‘Iteration

Iteration in programming is the process of repeating a set of instructions multiple times. The video mentions iteration as a key concept in programming, where tasks can be repeated by the computer, emphasizing its importance in performing repetitive tasks efficiently.

πŸ’‘Decomposition

Decomposition is a problem-solving technique where a large, complex task is broken down into smaller, more manageable subtasks. The video describes programming as a process of decomposition, where the big problem is divided into simple programming steps that the computer can follow to solve the overall problem.

πŸ’‘Syntax Error

A syntax error occurs when a programmer makes a mistake in the structure of the code, such as incorrect use of keywords, missing brackets, or wrong punctuation. The video explains the concept of syntax errors and emphasizes the importance of careful coding to avoid them, using examples from the script where missing quotation marks or incorrect use of an equals sign cause errors.

πŸ’‘Case Sensitivity

Case sensitivity in programming refers to the programming language's ability to distinguish between letters of different cases (upper and lower). The video points out that Python is a case-sensitive language, meaning that 'print' and 'PRINT' are treated as different keywords, and using the wrong case will result in a syntax error.

Highlights

Introduction to a series of video lectures on learning Python programming aimed at GCSE exam syllabus students.

Explanation of various computer languages with a focus on Python for its ease of use and readability.

Definition of a programming language as a set of vocabulary and grammatical rules for instructing computers.

Overview of the layers of programming, from hardware to high-level languages.

Introduction to key programming concepts such as sequencing, selection, and iteration.

Discussion on the importance of syntax in programming and how it differs from human languages.

Explanation of basic programming instructions including input, output, and mathematical operations.

Introduction to Python as a powerful, high-level programming language with various uses.

Python's design philosophy that emphasizes simplicity and code readability.

Popularity of Python based on web searches and its rise in recent years.

Use of an IDE (Integrated Development Environment) for Python programming, specifically IDLE.

Demonstration of writing and running a simple Python program using IDLE.

Importance of syntax in Python, including correct use of keywords, brackets, and quotation marks.

The interactive nature of Python programs demonstrated with user input and output.

Explanation of syntax errors and the importance of careful typing in programming.

Use of color coding in IDLE to help identify syntax errors.

Guidance on how to approach debugging and fixing syntax errors in Python.

Extension exercises suggested for practice, including calculating the area of a triangle and days alive based on age.

Transcripts

play00:01

[Music]

play00:10

hello and welcome to another series of

play00:13

video lectures this series is going to

play00:16

be about learning Python programming and

play00:18

it's aimed at people studying the GCSE

play00:21

exam syllabus so there are lots of

play00:25

different computer languages out there

play00:26

there are some examples here the one

play00:29

we're particularly going to use is

play00:31

called Python and I'll explain why are

play00:33

using it later on but of course there's

play00:35

many other really good programming

play00:36

languages that can be used

play00:39

so really today's but understanding what

play00:42

a programming language is how to go

play00:44

about starting to write programs in

play00:46

Python and starting to think about

play00:49

things like the syntax and how we

play00:52

construct statements the Python can

play00:54

understand so Python is a programming

play00:58

language what is a programming language

play01:01

well it's a vocabulary and set of

play01:04

grammatical rules for instructing

play01:06

computer to perform a specific task so

play01:11

if you have a look at this little

play01:12

diagram here we can see that down the

play01:16

bottom we've got the actual physical

play01:19

hardware that's inside your computer all

play01:22

those transistors and circuit gates and

play01:25

things like that and then we've got that

play01:28

you know how do we talk to a computer

play01:29

well computers understand ones and zeros

play01:33

but humans aren't very good

play01:35

understanding ones and zeros so we've

play01:37

built lots of different types of

play01:39

programming language on top of this that

play01:42

we can understand but that can be

play01:44

converted into machine language machine

play01:47

code ones and zeros very easily for the

play01:50

computer to understand so the ones at

play01:55

the top what we call the high-level

play01:56

languages and then towards the bottom

play01:58

we've got things like assembly which is

play02:01

a low-level language that you will

play02:03

practice a little bit maybe at a level

play02:06

depending on which exam syllabus you're

play02:09

following so the term programming

play02:12

language usually refers to the

play02:14

high-level programs and there's a big

play02:16

example here some of the more famous

play02:18

ones might be C C++ C sharp you've got

play02:22

things like jab

play02:24

you've got things like JavaScript as

play02:26

well lots of different types of language

play02:29

each language has a unique set of

play02:31

keywords so words that it can understand

play02:34

and a special syntax basically grammar

play02:39

rules for organizing program

play02:41

instructions a program is just a

play02:45

sequence of instructions that specifies

play02:48

how to perform a computation and this

play02:51

might be something mathematical for

play02:53

example solving equations or it might be

play02:56

searching replacing text in a document

play02:58

early computers in the 1940s and 50s

play03:01

what we usually just carrying out basic

play03:04

mathematical operations they could just

play03:07

do it a lot faster than people we can

play03:10

describe programming as the process of

play03:13

breaking a large complex task into

play03:15

smaller and smaller subtasks and these

play03:18

the ones we design a solution to and

play03:20

they work together to solve the big

play03:22

problem and when we divide big problems

play03:25

into small problems there's a special

play03:27

name for that and it's called

play03:30

decomposition I'll often talk about

play03:35

decomposing problems dividing them two

play03:38

simple programming steps that we can

play03:40

make and that the computer can follow

play03:42

and complete a big problem all right so

play03:46

there are key ideas in every programming

play03:49

language and the key idea is that we're

play03:52

going to look at first of all our

play03:53

sequencing putting instructions in the

play03:56

correct order selection the computer can

play04:00

choose different options depending on

play04:02

conditions present in your program and

play04:05

iteration tasks can be repeated multiple

play04:08

times by the computer so it doesn't

play04:12

matter which programming language you're

play04:13

looking at it's always going to involve

play04:15

sequencing selection and iteration put

play04:19

everything in the right order let the

play04:22

computer make choices depending on

play04:23

conditions and repeat steps that have to

play04:26

be done many times computers are really

play04:28

good at doing that to this end there are

play04:31

some basic instructions that will appear

play04:33

in every programming language you're

play04:35

always going to have input

play04:37

it's always gonna be some way to get

play04:38

data into your program you can have

play04:41

output you've got to be able to show the

play04:45

result of these computations maths

play04:48

computers are great at maths there's

play04:50

always a way to perform mathematical

play04:51

operations conditional execution is it

play04:57

the right password or the wrong password

play04:59

is it somebody under the age of 15 is it

play05:03

somebody over the age of 15 do different

play05:05

things in different circumstances

play05:07

this is conditions and as I say we're

play05:09

always gonna have a lot of repetition

play05:11

computers perform the same tasks many

play05:13

many times they're very good at doing

play05:15

that so bringing us on to Python Python

play05:19

I think at the time of recording 3.7 is

play05:23

the latest addition

play05:24

but generally any version 3 would be

play05:27

fine for this Python is a powerful

play05:29

programming language it's a high-level

play05:32

language and it can be has lots of

play05:34

different uses it says web development

play05:36

here but it's a great scripting language

play05:38

you can do lots of things with Python

play05:40

it's design philosophy emphasizes

play05:43

simplicity and code readability and it's

play05:47

syntax allows programmers to express

play05:50

concepts in fewer lines of code than

play05:53

would be possible in languages such as C

play05:56

so really it's simple to use it's

play05:59

readable it's got a syntax that allows

play06:02

you to write quite complex programs

play06:04

quite quickly and easily it's a great

play06:07

beginner language the language provides

play06:12

the constructs intended to enable clear

play06:14

programs and both a small on a large

play06:16

scale so you can do quick simple

play06:18

programs you can do quite advanced

play06:20

programs with it it's free it's open

play06:23

source I've got a community-based

play06:25

development model so you can find it on

play06:28

many different systems all right Python

play06:32

is really great language for learning

play06:34

programming but it's also useful if

play06:36

you're a more advanced programmer as

play06:38

well it's very popular so you look here

play06:40

at some evidence why do I say it's

play06:42

popular this is these are some graphs by

play06:46

The Economist magazine based on web

play06:49

searches for different

play06:51

gramming languages so you can see the

play06:53

worldwide here python is the fourth most

play06:57

popular language worldwide and you can

play06:59

see that has gone up a lot in popularity

play07:02

in recent years and if you just look in

play07:05

America it's actually the most popular

play07:08

programming language based on web

play07:10

searches recently overtaking Java this

play07:15

is another graph this is from Stack

play07:17

Overflow based on question views in

play07:20

World Bank high-income countries if you

play07:23

don't know what Stack Overflow is you'll

play07:25

learn Stack Overflow is a website where

play07:27

people discuss programming questions and

play07:30

issues so if you're not sure how to do

play07:32

something in Python and you go to a

play07:34

Google search and you type in Python how

play07:37

do I do

play07:37

blankety-blank most of the search

play07:40

results come back will probably be from

play07:42

Stack Overflow but you can see here very

play07:44

recently Python has become the most

play07:46

popular language on that web site

play07:51

overtaking other language such as

play07:53

JavaScript and Java of course all the

play07:56

languages on this list are really good

play07:58

Java Script is great Java's great Chavez

play08:00

what I study when I was at university

play08:02

good language c-sharp is really useful

play08:05

you got C++ which is really powerful PHP

play08:08

is used a lot of web development

play08:10

materials and they're all good languages

play08:12

we're just taking Python it's nice easy

play08:15

to learn language and it's very useful

play08:18

and very popular so to program in Python

play08:22

we like to use some special software

play08:24

what we call an IDE integrated

play08:27

development environment and this is just

play08:29

software that allows us to program

play08:31

easily that gives us some tools to make

play08:34

it a bit more pleasant a little bit more

play08:36

simpler to use you could use any text

play08:38

editor really you could write it almost

play08:41

directly into your command line but

play08:43

using a special piece of software just

play08:45

makes it a bit more user friendly there

play08:47

are lots of these IDs available that you

play08:50

can use with Python we're going to use a

play08:52

special one called

play08:53

idle and this is the one that comes with

play08:56

Python a standard so if you download the

play08:59

Python programming language onto your

play09:01

computer it will come with idle so it's

play09:04

not the most power

play09:05

IDE doesn't have the greatest range of

play09:07

features but it's free it comes with a

play09:09

programming language and that's the one

play09:11

we're going to be using if you want to

play09:13

use a different ID that's fine you just

play09:15

the screenshots and things will look a

play09:17

little bit different okay

play09:21

so when you first open Python idle the I

play09:24

kind of look something like this often

play09:27

it starts in what we call shell mode and

play09:31

this allows you to write programs one at

play09:34

a time you write one command you press

play09:36

ENTER it runs it you're type in the next

play09:39

command it runs it but this is not

play09:41

really what we want we want to write the

play09:43

whole program and run it in one go so

play09:46

you might need to reconfigure it to do

play09:49

that go to options go to configure idle

play09:53

if you want to you can change things

play09:56

like font and size but really I'd like

play09:59

you to go to the general tab and then

play10:01

select open edit window close it reopen

play10:06

it and that will give you something it

play10:08

looks like this and means you can just

play10:10

type all your program in one go save it

play10:12

run it all right let's look at a very

play10:16

simple program print hello so open up

play10:21

the window type it in press f5 it'll ask

play10:27

you to save it save it in somewhere

play10:28

where you know where it's gonna be give

play10:30

it a sensible name like hello or first

play10:33

program and run it what's gonna happen

play10:37

it's gonna open up the shell window it's

play10:39

gonna run it and it's just gonna display

play10:41

the word hello very simple

play10:44

congratulations you're a programmer if

play10:46

you can do lots of instructions like

play10:48

that together you're gonna write really

play10:50

nice complicated programs they're gonna

play10:53

be a lot of fun so what should you do

play10:56

now change it change the text change

play11:00

your own message maybe add another print

play11:02

line for example print good bye okay my

play11:11

handwriting is really bad that looks a

play11:12

bit small and then run it see what

play11:15

happens when you have two lines well

play11:17

doing programming you've got to

play11:19

experiment play with it

play11:20

see what you can get to happen try and

play11:22

break it see what happens if you make a

play11:24

mistake it's all about experimentation

play11:26

but if you look at that very simple

play11:29

first line here you can already see some

play11:32

some features that you need to know

play11:35

about we've got a keyword here that's

play11:38

print this is a special word that the

play11:41

computer understands Python Idol makes

play11:44

it display in purple so we know that

play11:46

it's a keyword so if you type in a

play11:48

keyword it'll come up in purple if it

play11:51

doesn't maybe you've made a mistake so

play11:55

we have brackets around what we want to

play11:57

print brackets are important make sure

play12:00

you open and close them and then we've

play12:02

got some text hello because it's text

play12:06

we're going to put it in inverted commas

play12:08

speech marks and that's how we always do

play12:12

text it's always in speech marks and it

play12:16

will display in green so you know that

play12:18

it's text if you write some text and

play12:20

it's not green you probably forgot one

play12:23

of the inverted commas either at the

play12:25

beginning of the end or both so again

play12:29

make sure you get the right syntax is

play12:31

very important and I'll discuss that

play12:32

again a little bit later so once you've

play12:36

done that it's a good idea to kind of

play12:37

rearrange your windows just to make

play12:39

programming easier what I like to do and

play12:42

what I teach my students is that we have

play12:43

the editor on one side and we have the

play12:46

shell in the other so we can type a code

play12:48

save it run it and it'll display what's

play12:52

happening over here and that just makes

play12:55

it easy to kind of see them both

play12:56

together especially if you've got any

play12:58

errors it's easy to try and do some bug

play13:00

hunting and fix those mistakes sure I

play13:03

have to do this I just think it makes it

play13:05

easier so in the shell window which is

play13:08

this one over here you can type things

play13:11

in directly like basic math or you can

play13:14

type in programming instructions one at

play13:16

a time but generally we don't want to do

play13:18

that we're going to write them in the

play13:20

editor so that we can save them and use

play13:23

them later

play13:26

all right let's try something a little

play13:27

bit different something it's more

play13:29

interactive

play13:30

I'd like you to type this in save it run

play13:34

it again give it a sensible name before

play13:37

you run it it's always a good idea to

play13:38

think what's gonna happen when I run

play13:40

this program what's what's gonna do name

play13:44

equals input what is your name

play13:47

print hello comma name okay what's

play13:52

happening here all right well we've got

play13:54

some text here so it's gonna display

play13:56

what is your name

play13:58

question mark and the keyword is input

play14:01

what does input do

play14:03

well maybe it's sending information into

play14:05

the computer okay and where is it

play14:08

sending that into the computer well

play14:10

maybe we've created this thing called

play14:12

name technically it's called a variable

play14:15

but we'll look at that later and we're

play14:17

gonna whatever they type in we're going

play14:19

to store it under name and the next line

play14:22

we're going to print out some text which

play14:24

is a low and then common name so maybe

play14:27

whatever the user is typed in here that

play14:31

was stored in here is now going to get

play14:34

printed out it's going to be output hmm

play14:37

all right that's what I think it's gonna

play14:38

happen

play14:39

so I'm gonna run it and I'm gonna see

play14:41

and check so again

play14:44

programming is all about experimentation

play14:46

you just have to try and guess what

play14:48

things are gonna do have a think about

play14:50

it run it see if that's what really

play14:52

happens if not think about why so again

play14:56

maybe save it as hello dot P wire or

play14:59

something similar again you can press f5

play15:01

to run it and something like this should

play15:04

happen so we've got the text what is

play15:09

your name the user type something in Bob

play15:13

mcbomb

play15:13

not my real name by the way and it

play15:16

prints out hello Bob body Bobby my body

play15:19

and Dottie okay I can't speak at the

play15:22

moment but whatever the user types in

play15:24

here is what gets printed out here run

play15:27

it two or three times change the name

play15:29

and you'll see it'll keep printing out

play15:31

different things okay this is a good

play15:35

time to talk about syntax errors so

play15:37

unless you are some

play15:40

sort of superhero with magical powers

play15:43

it's very difficult to type in programs

play15:45

without making a mistake even

play15:48

experienced programmers when working on

play15:50

programs even more than 10 or 15 lines

play15:52

of code tend to make little mistakes and

play15:56

these produces what we call a syntax

play15:58

error

play15:59

Computers are very literal they do

play16:01

exactly what you tell them they can't

play16:04

guess so if you make a very slight

play16:07

mistake they're not going to understand

play16:09

it and you're going to get some sort of

play16:11

error message and that's not the

play16:12

computer being mean to you it's just the

play16:14

computer saying I'm sorry I don't

play16:16

understand could you say that again okay

play16:20

so things like the colons the brackets

play16:24

speech marks of post Rafi spelling of

play16:26

key words it's got to be perfect it's

play16:30

not like if you're writing an English

play16:31

essay and you forget a capital letter or

play16:35

you forget a comma you might not get

play16:38

such a good grade but everybody still

play16:40

understands it

play16:41

programming is just not going to work so

play16:43

you've got to make sure you very careful

play16:45

with how you type things in so although

play16:48

we understand it if you make a minor

play16:51

mistake the computer will not understand

play16:53

it and you're gonna have to check it and

play16:55

fix it and run it again but don't worry

play16:57

about that everybody makes mistakes I

play16:59

make silly errors all the time it's ok

play17:03

so an IDE like Python Idol has different

play17:07

ways of trying to help you understand if

play17:10

you've made a mistake

play17:12

one simple feature that Idol uses is

play17:14

color coding so I've already mentioned

play17:17

that things like the keywords will be in

play17:20

purple so if you type in for example

play17:26

print instead of print it's probably not

play17:29

going to appear in purple because that's

play17:31

not a keyword so you can see straight

play17:33

away that it's wrong in the same way the

play17:37

text should appear in green in Python

play17:40

Idol so if you write some text that you

play17:42

want printed out exactly and it's not

play17:44

green in the editor window that's

play17:46

probably because you made a mistake with

play17:48

your inverted commas your speech marks

play17:50

so again you can kind of tell if you've

play17:53

made a mistake as

play17:54

you're typing it more powerful IEDs have

play17:57

even better ways of detecting and

play17:59

showing you that you've made an error

play18:01

but idle is quite simple but color

play18:04

coding is still a good feature so again

play18:07

we've got to use the correct syntax

play18:09

print hello works

play18:11

however print hello or print hello here

play18:15

this one's got no brackets no speech

play18:17

marks this one doesn't have the speech

play18:19

marks neither of these will run you'll

play18:21

get an error it's also case sensitive

play18:26

especially for things like keywords

play18:28

print hello works but print PRI and T

play18:33

capital letters will produce a mistake

play18:36

an error message of some kind okay so

play18:39

that works this doesn't so be careful

play18:42

you need to learn to be able to spot and

play18:47

correct common syntax errors if you're

play18:50

doing this at home then you've got to do

play18:52

all this yourself if you're doing it in

play18:54

the class you've got a bit of help but

play18:56

what I tell all my students is if you

play18:59

get some sort of error message it's not

play19:01

that the computer is broken you've

play19:03

probably just made a mistake and it's

play19:05

usually something really simple so check

play19:07

your code carefully check it again maybe

play19:10

check it a third time again it will

play19:14

almost certainly be something very basic

play19:16

that you've forgotten it's usually not a

play19:17

big mistake usually something very small

play19:20

if you're doing this in the computer lab

play19:22

at school please ask the people on

play19:25

either side of you ask some DS better

play19:27

programming to take a look at it of

play19:28

course you can ask your teacher but

play19:36

please remember oh my pen seems to going

play19:39

a bit funny there okay never mind

play19:41

please remember your teacher is really

play19:43

busy you're gonna have lots of students

play19:45

in the class with questions make sure

play19:48

you've done all these steps first before

play19:50

you ask your teacher just to make sure

play19:52

they can make most efficient use of

play19:54

their time okay so here are some

play19:57

examples of some syntax errors this is a

play20:00

really basic one here you see it's a

play20:03

mistake over here and it's coming up you

play20:05

got a syntax error invalid syntax

play20:08

and straightaway we can see that this

play20:10

text is not in green that's because we

play20:14

forgot our inverted commas so okay that

play20:16

was our mistake I need to go back change

play20:18

that run it again all right

play20:20

I've run another program and I'm getting

play20:23

a traceback error oh it doesn't even so

play20:28

it doesn't even do what well it doesn't

play20:30

run because there's a mistake so it's

play20:32

started to try and run the program there

play20:34

is a problem and it comes up the trace

play20:36

back error which is saying help I don't

play20:38

know what you're saying I don't

play20:39

understand please say it again in a way

play20:42

that I will understand and it tells you

play20:45

which line of code the mistake is in and

play20:48

then it tells you the line that the

play20:51

mistake is in as well so name - input

play20:56

what is your name oh well it's not a -

play20:59

is it I meant to put an equals should be

play21:02

an equals in there I just made a mistake

play21:05

so there you go it's trying to be help

play21:08

what tells me where the mistake is

play21:10

gives me the line so I can go back and

play21:12

fix it so that of course is an equals it

play21:15

should be in there I can go back to my

play21:16

main program change it run it it'll be

play21:18

great all right let's try one more

play21:21

program this one's a little bit more

play21:22

complicated first of all take a look at

play21:25

it what do you think is gonna happen

play21:27

well tell me oh I can't hear you

play21:30

obviously okay so we're going to print

play21:32

our welcome

play21:34

we think that's probably pretty simple

play21:36

calories equals input how many calories

play21:39

have you eaten today well we know what

play21:41

input is it's when we want to send

play21:44

information to the program we can type

play21:47

it in it gets added to the program so

play21:49

the question is how many calories have

play21:51

you eaten today

play21:52

okay we'll type in a number and then

play21:55

that's going to be stored as calories

play21:58

cows left equals 2,000 minus into

play22:02

calories well we got the minus here so

play22:05

this is probably gonna be some kind of

play22:06

math 2,000 calories minus whatever the

play22:10

user typed in earlier okay that's fine

play22:14

why does it say int here oh that's a

play22:16

plus a bit of a new one

play22:18

okay come back to that in a second print

play22:22

you can eat cows left more calories

play22:26

today so it's going to print out this

play22:28

text exactly and this text well that's

play22:32

whatever the result of this calculation

play22:35

is going to be so that's how I would try

play22:39

and work out what it means step by step

play22:41

that I've run it and just check that's

play22:43

what really happens so we'll come back

play22:47

to this where it says int and this is

play22:50

because when we type something into the

play22:53

computer for example at this stage the

play22:55

computer always thinks that it's text

play22:57

but now we want to do some math we can't

play23:01

do math for text we have to tell the

play23:03

computer hey this is an integer it's an

play23:08

int in Python programming speak it's an

play23:11

integer value it's a number so now you

play23:14

can do math if you don't say int

play23:16

calories it's gonna be a bit weird

play23:18

because it's gonna be 2,000 minus text

play23:21

and that doesn't really compute so we

play23:25

run that yeah it says welcome how many

play23:28

calories have you eaten today

play23:30

I typed in 789 and it says you can eat

play23:35

1211 more calories today so I'm gonna go

play23:38

get a ton of ice cream so again try it

play23:40

run it run it a few times any syntax

play23:42

errors you know keep trying it again

play23:46

here are some extension programs you can

play23:49

try don't have to do these I'm not going

play23:51

to put up the solutions but if you want

play23:53

a bit of practice create a program that

play23:55

will work out the area of any triangle

play23:58

remembering the formula the area of a

play24:01

triangle is 1/2 times the base times the

play24:03

height so you'll need to ask the user to

play24:05

type in two values the base and the

play24:09

height to have two input statements

play24:11

you'll need to do some maths so you'll

play24:14

need to multiply the base and the height

play24:17

together and then divide it by two or

play24:19

multiply by 0.5 and print the result

play24:23

next extension write a program to work

play24:26

out how many days you've been alive for

play24:28

so this program would ask the user to

play24:31

type in

play24:32

how many years old they are what their

play24:34

ages and then it needs to take that

play24:36

number and multiply it by 365 and print

play24:39

the result so have a go at that if you

play24:41

want if you can't quite get all that

play24:43

working just now don't worry we will go

play24:45

through some more complex programs in

play24:47

the next lesson

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Python ProgrammingGCSE SyllabusCoding BasicsSyntax RulesProgramming LanguageIDE ToolsInput OutputVariablesConditionalsLoopsBeginner FriendlyEducational Series