0% found this document useful (0 votes)
6 views

Python programming

The document outlines key concepts in Python programming, focusing on the differences between input and output, the use of variables, and iteration through loops. It explains how to handle user input and display output, as well as common programming errors such as syntax and logic errors. Additionally, it covers data types and their purposes in Python, providing examples for clarity.

Uploaded by

Janika Frimpong
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python programming

The document outlines key concepts in Python programming, focusing on the differences between input and output, the use of variables, and iteration through loops. It explains how to handle user input and display output, as well as common programming errors such as syntax and logic errors. Additionally, it covers data types and their purposes in Python, providing examples for clarity.

Uploaded by

Janika Frimpong
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Do now task – Get a

whiteboard
What is the difference between input and
output in Python? Provide an example for
each
Python programming
Revision lesson
Lesson Objective
• Understand what a variable is and why it’s important in programming.
• Learn the difference between input (user gives data) and output
(program shows data).
• Understand how iteration works, using for loops and while loops to
repeat tasks.
• Recognize common programming errors (syntax and logic) and learn
ways to write error-free code.
What is Iteration • Is a process of repeating steps
?
There are two techniques
- FOR LOOPS - Repeat for a fixed
number of times.
- WHILE LOOPS - Repeat as long as a
condition is true.
FOR LOOPS :
Repeat for a
Here are some fixed number of
different coding times
examples of FOR
LOOPS

# this generates numbers from 1 to 5 where this stops


before 6

# For each of the number in the range the code prints out
the value of i
Here are some WHILE LOOPS :
different coding Repeat as long
examples of as a condition
WHILE LOOPS is true
Input
#count starts at 0
#the loop runs as long a count is less
than 5

#Prints the current value of count


#Increases count by 1
Output
Sequence
• Is a set of step-by-step instructions that a computer follows to solve a
problem.
Code Example

Input

Output
Selection

- In algorithms, selections are decisions or


question.
- Is represented by the instructions such
as IF, THEN and ELSE.
- IF-THEN is part of the statement. Code Example
- The ELSE – part causes another path to
be followed, the condition is false.
Variables
• A variable is a named location in which to store values.
• Output is when the user gets something from the computer (such as a
message).
• Input is when a user enters data into a computer.

Input Output
Variables
Talk in pairs and decide which of these are good variable
names.
• postcode • first name
• number1
• print
• 2024_sales
• avg_score • totalSales
• 42
• zoo_closing time
• Surname
Variables ANSWERS
Talk in pairs and decide which of these are good variable
names.
• postcode • first name

• number1 • 2024_sales

• print • totalSales

• avg_score • zoo_closing time

• 42 • Surname
Input and output
• Instead of entering the name into our programming we could ask the
user to enter a first name.
display a message to ask
the user to input their
1 print("What’s your name?") name
2 f_name = input() the input command will
3 print("Hello", f_name) wait until they enter a
value and then store that
in the variable f_name
display a message saying
"Hello“ and the name
they entered
Variables
What is wrong with these variable names?
• print
• 42
• first name
• 2024_sales
• zoo_closing time
• Surname
Robust Programming
Is the ability of a computer system to cope
with errors during performance and cope
with incorrect input.
The two type of errors
• Syntax Errors
• Logic Errors
A spelling or grammatical
mistake in the program

Incorrectly spelled variables

Grammatical
Mistake

Syntax Errors

Spelling Mistake

Missing punctuation
(quotes and brackets)
A mistake in the logic of the
program
Missing all altogether

Use the wrong Data type


Logic Errors Be in the wrong sequence

Have the wrong


Boolean(true or false)
expression.
Variables ANSWERS
What is wrong with these variable names?
• print print is a dedicated word that does
something
• 42 starts with a number
has a space in the name
• first name
starts with a number
• 2024_sales
has a space in the name
• zoo_closing time
starts with a capital letter. Although this will not
• Surname cause an error it is not the convention used by
programmers.
• The data type
determines what
type of value the
variable will
hold.
Data Types and Operators
Data type Purpose Example

Integer Whole numbers 27

Real (also called Float) Decimal numbers 27.5

Char (also called Character) A single alphanumeric character A

String One or more alphanumeric characters ABC

Boolean TRUE/FALSE TRUE


Data Types and Operators Think about
What type of data is 7 in Python?
Integer

What type of data is "apple" in Python?


String

What is the data type of the value 3.14 in Python?

Float
Task
• Go on to teams finish off all the task from lesson
7
Plenary
 What part of Python programming do you feel most confident about?

 What part do you still find difficult ?

You might also like