0% found this document useful (0 votes)
5 views16 pages

Year9 Variables DataTypes Algorithms v2

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)
5 views16 pages

Year9 Variables DataTypes Algorithms v2

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/ 16

Variables, Data Types, Algorithms

& Flowcharts in Python

 Year 9 Computer Science


 Teacher: Kunle Olumodeji
Learning Objectives

 1. Define variables
 2. Explain main data types
 3. Assign values and identify types
 4. Understand algorithms
 5. Draw flowcharts
What is a Variable?

 A variable is a name that stores a value in memory.


 Analogy: Labelled box for storing data.
 Rules:
 - Start with letter/underscore
 - No spaces
 - Case sensitive
 Example:
 age = 14
 name = 'Aisha'
 is_student = True
 height = 1.65
Data Types

 int: 5, -10 (whole numbers)


 float: 3.14, -2.0 (decimals)
 str: 'hello', '123' (text)
 bool: True, False (logical values)
 Use type() to check types
Examples &
Demonstrations
 a = 10
 b = 3.0
 c = '10'
 d = False
 e=b*a
 Predict values and types.
Common Errors

 1. Adding int + str causes error


 2. True vs true (Python uses True)
 3. Variable names: no spaces, no starting with
numbers
Activity 1 – Worksheet

 Fill blanks for variables


 Classify types of given values
 Write code asking user for name & age, print
message.
What is an Algorithm?

 Step-by-step procedure to solve a problem.


 Examples: recipe for tea, getting ready for school.
Flowcharts

 Graphical representation using symbols:


 Oval: Start/End
 Rectangle: Process
 Diamond: Decision
 Arrow: Flow control
Algorithm + Flowchart
Example
 Problem: Check if number is even or odd
 Steps: Start → Input → Decision → Output → End
Activity 2 – Algorithms &
Flowcharts
 Choose problem: Voting age, average scores,
largest number
 Write algorithm steps
 Draw flowchart
Python Code Example

 n = int(input('Enter number: '))


 if n%2==0:
 print('Even')
 else:
 print('Odd')
Assessment / Exit Quiz

 1. Type of 5/2?
 2. name=5 then print(name+' here')?
 3. What is an algorithm?
 4. Flowchart symbol for decision?
Review & Homework

 Review: variables, data types, algorithm, flowchart


 Homework: Write algorithm & flowchart, code it in
Python
Flowchart Symbols —
Explanation & Uses
 Start / End (Terminator) - Oval
 • Explanation: Marks the beginning or end of a process.
 • Uses: Start program, Stop/End.

 Process - Rectangle
 • Explanation: An action or instruction (e.g., calculation or assignment).
 • Uses: total = a + b, update counters.

 Input / Output - Parallelogram


 • Explanation: Data entering or leaving (input from user, output to screen).
 • Uses: input(), print(), read file, write file.

 Decision - Diamond
 • Explanation: A conditional/branching point (yes/no or true/false).
 • Uses: if age >= 18? then branch accordingly.

 Connector - Small circle


 • Explanation: Connects separated parts of a flowchart (flow continues elsewhere).
 • Uses: Jump between flowchart sections, multi-page charts.

 Flowline / Arrow
 • Explanation: Shows the flow direction between steps.
 • Uses: Connect steps in correct order.

 Predefined Process (Subroutine) - Rectangle with double-struck sides


 • Explanation: Represents a named, reusable process/task.
 • Uses: Call a function or subroutine (e.g., 'CalculateAverage').

 Annotation / Comment - Bracket or note


 • Explanation: Extra information or clarifications.
 • Uses: Add notes, explain assumptions or special cases.
Flowchart → Code: Quick
Mapping & Example
 Quick mapping of symbols to Python code:

 • Start/End -> program start / program end


 • Process -> assignment, calculation (e.g., total = a + b)
 • Input/Output -> input() / print()
 • Decision -> if / elif / else (condition checks)

 Simple example (Even/Odd) - Steps:


 1. Start
 2. Input number n
 3. Decision: n % 2 == 0 ?
 - Yes: print 'Even'
 - No: print 'Odd'
 4. End

 Teacher tip: When drawing flowcharts, always label decision arrows (Yes/No or
True/False).

You might also like