0% found this document useful (0 votes)
4 views19 pages

Lesson 5 Programming Tecniques - Students 9b It 2

The document provides an overview of Python programming concepts, focusing on syntax errors, data types, variables, and expressions. It outlines the different data types such as integers, real numbers, Boolean, characters, and strings, along with their definitions and examples. Additionally, it emphasizes the importance of syntax in programming and includes a task for students to complete on Microsoft Teams.

Uploaded by

Janika Frimpong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views19 pages

Lesson 5 Programming Tecniques - Students 9b It 2

The document provides an overview of Python programming concepts, focusing on syntax errors, data types, variables, and expressions. It outlines the different data types such as integers, real numbers, Boolean, characters, and strings, along with their definitions and examples. Additionally, it emphasizes the importance of syntax in programming and includes a task for students to complete on Microsoft Teams.

Uploaded by

Janika Frimpong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Starter

 Go on teams, algorithm, complete lesson 5


Starter- Python-Syntax-Errors
Type in the following Is there an error?
into the SHELL: What is the reason?
print (hello world)
The quotation marks
print("hello world")

print ”hello world”


Missing Brackets
Answer
print (“hello world)
print("hello world")
s
Missing closing double quote

print("hello world")

Print is incorrectly capitalized.


Print (“hello world”)
print("hello world")

print (“hello world” Missing closing parenthesis )


print("hello world")

print (“Hello World”); semicolons,


print("Hello World")
Programming
Techniques
Lesson 5
Learning Objectives

 Understand what different data types can store.


 Identify different types of operators.
 Understand what a variable is.
 Be able to use Python idle to run simple
statements.
 Keywords(data types, integer, Boolean,
character, real, string, operators, variable,
assignment, AND, OR, NOT )
Data Types
When you create a variable, many programming languages require
you to state the type of data you want to store in it.

Different types of data require different amounts of memory and,


therefore, the computer needs to know how much memory to
allocate to a particular variable.

The main data types are:

Integer Real Boolean Char


Integer
An integer is a whole number without a fractional part (decimal place).

.7
5
5
Here are some examples of integers:

Age = 14 Score = 75 People = 4


Real
Real numbers (also known as floating point) can have a fractional
part (decimal place).

.7
5
5
Here are some examples of real numbers:

Temperature =
Price = 1.84 Height = 1.85
18.5
Boolean
The Boolean data type supports only two different values:
True and False.

These values are represented using binary.

0 = False 1 = True
Overdue = Authorised =
False True
Character

The character data type stores a single alphanumeric character.

This could be a letter, number or symbol.

Here are some examples of characters:

Gender = F Grade = B Initial = H


String

A string is a group of characters.

Strings are usually enclosed within quote marks “ ”.

Here are some examples of strings:

Name = Postcode = “N1


City = “London”
“Alex” 5BH”
Expressions

Try typing some of these expression in Python idle,


pressing return after each one

print (2+2+2+2+2)

print (8*6)

print (10-5+6)

print ( 2 + 2)

What happens?
• Expressions
You have been using expressions
2 values and an operator
Even the 2+2+2+2 follows this
rule

2+2 addition

Operators, you already know. 2-2 subtraction

Perhaps the multiplication is multiplicatio


2*2
n
written differently as a * (on the
2/2 division
number pad)
Conditions Boolean values can be true or false.

6>5 True

Operator 3 <= 4 False


Operator Name
Sign False
2 == 3
< Less than
Error, should be ==
4=5
> Greater than
True
<= Less than or equal to 45 != 2
Error – remember data types
Greater than or equal 3 == 3.0
>=
to
Eggs > pizza Depends on the values of
== Equal to Eggs and pizza variables.

!= Not equal to
Boolean operators
 There are 3 Boolean operators: AND, OR, NOT.

Operator Evaluates to True if: Evaluates to False if:

AND Both inputs are True Either inputs is False


Eg: 3<5 AND 2>1 Eg: 4<5 AND 10>20

OR Either input is True Both inputs are False


Eg: 1>8 OR 2==2 Eg: 1==8 OR 2<2

NOT Input is False Input is True


Eg. NOT (5>8) Eg: NOT (10>6)
• Syntax
 The syntax of a programming language is the set of rules that control if a
program is correct.

 You tried print (“Hello, World”) and it worked – a correct program.

 Try these  Syntax is CRITICAL in programming. A

print hello computer cannot take an educated guess


at your instructions.
print (hello)  Computers just follow exactly what you tell

PRINT(“hello”) them to do.

print (a + b)
print (5 + 6 / 7 +)
Variables
A variable is just a box with a number in it.

When we use variable in our code the computer


uses the value in the variable.

To store the value 15 in the variable and display it Now try these
spam = spam + 12
spam = 15 print (spam)
print (spam) spam = spam + spam
print (spam)
Try it. spam = spam * spam
print (spam)
Variables
This time we have 2 variables eggs and fizz
You can assign them by
eggs = 15
fizz = 10

In python eggs is not the same as


What be the output of the following, go on try it.
15
print( eggs )
EGGS.
print( eggs + fizz )
25
>>>nothing
Python is case sensitive which
spam = eggs + fizz
25
means YOU MUST BE CAREFUL
print( spam )
>>>nothing
eggs = fizz
10
print( eggs ) Traceback (most recent call last):
print( EGGS ) File "<pyshell#37>", line 1, in <module>
EGGS
NameError: name 'EGGS' is not defined
Task
 Pleaselog onto Microsoft Teams, click on
"Class notebook", close the page that
appears by clicking on the arrow, click
on your name folder, select 2.
Algorithm folder, complete lesson 5
Programming Techniques starter,
main activity and plenary
worksheet. All work must be
completed on Teams;
Plenary
What is a variable?
A named piece of memory that holds a value
which can be changed as a program is running

Giving a variable a value is known as


what?
Assignment

Which data type represents whole


numbers?
Integer

Which logical operator represents greater


than?
>

Which are the Boolean operators?

AND, OR and NOT

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy