0% found this document useful (0 votes)
3 views60 pages

Programming

The document provides an overview of computational thinking, focusing on pseudocode, algorithms, logic errors, loops, and subroutines. It explains the purpose and benefits of pseudocode in programming, outlines the concepts of iterations and loops, and discusses physical computing and iterative development. Additionally, it covers the importance of error correction, time and space complexity, and the role of prototypes in product development.

Uploaded by

sethlufwa7
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)
3 views60 pages

Programming

The document provides an overview of computational thinking, focusing on pseudocode, algorithms, logic errors, loops, and subroutines. It explains the purpose and benefits of pseudocode in programming, outlines the concepts of iterations and loops, and discusses physical computing and iterative development. Additionally, it covers the importance of error correction, time and space complexity, and the role of prototypes in product development.

Uploaded by

sethlufwa7
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/ 60

Chapter 1

Computational thinking and


programming
Pseudocode
What is Pseudocode?
• Pseudocode is a way of planning an algorithm or program using plain
English (or any language). It is a structured, informal method of
writing down the steps of a process or solution without using strict
programming syntax.

• Pseudocode is not executable by computers. It is simply a human-


readable way of representing the logic of a program or an algorithm.
Algorithm
• An algorithm is a step-by-step set of instructions or rules designed to
perform a specific task or solve a particular problem. It takes input,
processes it, and produces output in a finite amount of time.
• For example, a simple algorithm for adding two numbers would look
like this:
1.Take two numbers as input.
2.Add the numbers together.
3.Output the result.
Logic error
• A logic error is a type of programming mistake where the code runs
without crashing but produces incorrect or unintended results.
• This happens because the logic or reasoning behind the code is
flawed.
Common examples of logic errors:

•Using incorrect formulas or algorithms that


lead to wrong outputs.

•Misunderstanding the problem


requirements, leading to incorrect
implementation.

•Using the wrong condition in an if statement


or a loop.
pseudocode algorithm that allows only numbers between
100 and 200:

• START
• INPUT number
• IF number >= 100 AND number <= 200 THEN
• PRINT "The number is within the allowed range."
• ELSE
• PRINT "The number is outside the allowed range."
• END IF
• END
TO find even or odd
• START
• INPUT number
• IF number MOD 2 = 0 THEN
• PRINT "The number is even."
• ELSE
• PRINT "The number is odd."
• END IF
• END
We have a list of colors, and we
want to find out if a specific
color exists in the list.
• START
• INPUT color_to_find
• SET red TO "red"
• SET blue TO "blue"

• IF color_to_find = red OR color_to_find = blue THEN


• PRINT "Color found and it's either red or blue!"
• ELSE
• PRINT "Color not found or it's not red or blue"
EXAMPLES

•PAGE NO 18
•Pseudocode Algorithm
•Page no 23
•NO 6 Pseudocode Algorithm
Purpose of Pseudocode

Pseudocode serves multiple purposes:


• Helps plan algorithms: Before writing actual code, pseudocode allows
programmers to plan the steps involved in solving a problem.
• Clarifies logic: It helps break down the problem into simple, understandable
steps, making it easier to understand the flow of the solution.
• Bridge between problem and code: It acts as a bridge between a problem
statement and actual coding, providing a simple format for programmers to
work with.
• Communication tool: It allows programmers to share their ideas or
algorithms with others who may not be familiar with specific programming
languages. It uses natural language combined with structured logic.
Benefits of Using Pseudocode
• Easy to Write and Understand: Unlike programming languages,
pseudocode is in plain English and doesn't require knowledge of
programming languages to understand.
• Helps Spot Errors Early: By outlining the algorithm first, pseudocode
can help spot potential issues before writing actual code.
• Flexible: It can be adapted to various languages or environments
later.
• Teaches Logic: Pseudocode focuses on understanding the logic of
solving a problem, which is essential before diving into code.
When and Why Do We Use
Pseudocode?

When:
• During the planning phase of programming or algorithm design.
• Before writing actual code in a programming language.
• To break down complex problems into smaller, manageable steps.
• When trying to explain a process to others in a clear and simple manner.
Why:
• Easy to understand: Pseudocode is simpler and more readable than actual programming code.
• Error-free planning: It allows you to check the logic of an algorithm before starting to write the actual
code.
• Language-neutral: Pseudocode is not tied to any programming language, so it helps programmers of
different backgrounds understand the logic.
• Organize thoughts: Helps the programmer think through the logic clearly and logically, avoiding confusion
during actual coding.
Iterations
Definition:
An iteration is one complete pass through a loop. It means repeating
a set of instructions again and again.
• Example:
If a loop runs 5 times, it has 5 iterations.
Loops

Definition:
A loop is a programming structure that repeats a
section
of code as long as a certain condition is true.
Common types of loops:
•for loops
•while loops
Stopping a Loop

Definition:
A loop can be stopped early using a command
like break. This ends the loop before it would
normally finish.
Example:
In a loop that should run 10 times, a break
statement might stop it after 3 if a condition is met.
Incrementing
Definition:
Incrementing means increasing a
variable’s value, usually by 1. It is often
used to control how many times a loop
runs.
Example:
python
i = 0 i = i + 1 # or i += 1
For Loops

Definition:
A for loop is a type of loop used when you know in
advance how many times you want to repeat a block of
code.
Example:
python
for i in range(5): print(i)
This loop runs 5 times and prints the numbers 0 to 4.
Count-Controlled Loop in
(Pseudocode)

Count-Controlled Loop (Pseudocode)


• Definition:
A count-controlled loop repeats a set of
instructions a specific number of times. You
know in advance how many times it should
loop.
KEY features of Count Controlled
Loop

• It repeats a set of instructions a specific number of times, using a


counter that increases (or decreases) with each loop.
Details:
• The number of repetitions is known in advance.
• A counter variable keeps track of how many times the loop has run.
• The counter is automatically updated each time the loop runs.
Purpose of Count controlled
loop
1.Repetitive tasks: When you know exactly how many times you want
to repeat a task, a count-controlled loop is useful for automating that
repetition.
2.Simplified iteration: The loop's counter (usually a variable) keeps
track of how many times the loop has executed, making the logic easy
to understand and maintain.
3.Efficiency: It helps in limiting unnecessary iterations, as it will only run
for the exact number of times specified.
Flow chart to print 1 to 5
Count controlled loops in flow
chart
Draw all these flow charts using
word or Suitable Application
•Page no 19 figure 1.6
•Page no 20 figure 1.17
•Page no 42 figure 1.12
•Page no 43 figure 1.13
Subroutine
• A subroutine in programming is a set of instructions designed to
perform a specific task, packaged as a reusable unit.
• It’s also commonly known as a function, method, or procedure,
depending on the programming language.
Here's what makes subroutines
useful:
• 🧱 Modularity: Code is broken into small, manageable chunks.
• 🔁 Reusability: You can call the same code multiple times
without rewriting it.
• 🧼 Readability: Easier to understand and maintain.
• 🐞 Debugging: Easier to isolate and fix bugs.
Subroutine Vs Iteration
Feature Subroutine Iteration

Function Organizes code into reusable units Repeats a block of code

Runs automatically based on


Usage Called when needed
conditions

Syntax def, function, or method for, while, do-while

No automatic repetition unless


Repetition? Built specifically to repeat
coded

Focus Code organization and reuse Looping through tasks


Draw this flow chart in your note
book
•Page no 70
•Figure 1.33
Predefined Subroutine

A predefined subroutine is a ready-made


function provided by the
programming language or its standard library
that performs a common, often-used task.

print("Hello, world!") # 'print' is a predefined


subroutine
Loops in Text based programming.
For Loop
• Used when you know how many times you want to repeat
something.
• Python programming
for i in range(5):
print("Hello!")

This will print "Hello!" 5 times.


While Loop

• Used when you don’t know exactly how many times the loop should
run — it keeps running as long as the condition is true.
Python Example:
• count = 0
• while count < 5:
• print("Hello!")
• count += 1
Draw this table in your Notebook

•Page no 88
•Table 1.2
Python Data Types Table
Data Type Type Name Example Description
Whole numbers (no
Integer int 5, -10, 0 decimals)

Text enclosed in
String str "Hello", 'A' quotes

Numbers with
Float float 3.14, -0.5 decimal points

Represents logical
Boolean bool True, False values (true or false)

Collection of
List list [1, 2, 3], ["a"] ordered, changeable
items
Characters in Python – Summary Table

Concept Python Representation Example Explanation


Single letter, digit, or
Character str (length = 1) 'A', 'z', '7' symbol as a 1-length
string
You can check if it’s a
String length len(string) len('A') → 1 single character
Characters can be
Indexing string[index] 'Hello'[0] → 'H' accessed by position
(indexing)
Converts a character to
ASCII values ord(char) ord('A') → 65 its ASCII code
Converts ASCII code back
Character from code chr(number) chr(65) → 'A'
to character
Common Errors and Error correction
• Page no 88
• Table 1.2
And

• Page no 118
• Table 1.15
Two ways of comparing Algorithm
1. Time Complexity
• Time complexity refers to how the running time of an algorithm
changes as the size of the input increases.
• This is often expressed using Big O notation, which helps to classify
algorithms by how they perform relative to input size.
Constant time
Logarithmic time
Linear time
Quadratic time
Space Complexity

Space complexity refers to the amount of memory or storage space an


algorithm uses as the size of the input increases. Like time complexity,
space complexity is also often expressed using Big O notation. It helps
determine how much extra space an algorithm requires apart from
the input data.
• Constant space –
• Linear space
How to compare memory use of Two
Programs
Space Complexity:
• Space complexity measures how much memory a program uses as the
size of the input increases.
Static vs. Dynamic Memory Usage:
• Static Memory: Fixed memory used regardless of input size (e.g.,
variables, constants).
• Dynamic Memory: Memory that changes based on input (e.g., arrays,
linked lists).
3. Auxiliary Space:
• What it is: The extra memory used by a program excluding the input
data.
4. Memory Leaks:
• What it is: If a program doesn't release memory properly, it can cause
memory leaks.
• 5. Input Size and Data Structures:
Lab TASK
• Page no 127
• Program 1 and Program 2
• Page no 125
• Activity 1.16
• Write a program using for and loop condition to find out the Grades
for the Marks Obtained.
Physical computing
Physical Computing

Physical computing involves creating systems that


interact with the physical world using sensors,
actuators, microcontrollers, and software. It combines
hardware and software to build interactive projects.
Key Components of Physical
Computing
• Microcontrollers / Microprocessors
• Small computers like Arduino, Raspberry Pi, or Micro:bit.
• They process inputs and control outputs.
• Sensors
• Devices that detect physical changes (e.g., temperature, light,
motion).
• Examples: Light sensor, temperature sensor, motion sensor, touch
sensor.
• Actuators
• Components that perform actions (e.g., motors, LEDs, speakers).
• Examples: Servo motor, DC motor, LED lights.
• Power Supply
• Provides electrical power to the system (batteries, power adapters).
How Physical Computing Works:

• Sensors detect physical changes in the environment.


• The microcontroller reads data from sensors.
• The data is processed by the microcontroller’s program
(software).
• Based on the program, the microcontroller sends signals to
actuators to perform an action.
• Usually involves writing code in languages like Arduino (C/C++),
Python, or block-based programming.
Examples of Physical Computing
Projects:
• Light-activated alarm system
• Temperature monitoring device
• Automated plant watering system
• Interactive art installations
prototype
• A prototype is an early version of a product from which future
versions are developed. Engineers and product developers often
create these test versions
Steps in prototype development
Iterative development

• Iterative development is a product development method that


emphasizes flexibility and collaboration by designing, prototyping, and
testing smaller features within the overall product.
Two ways to guide Iterative development:

• Requirement focus: Software products must be functional


and user-friendly to meet the needs of target customers.

• Solution focus: A software solution typically has several


architectural layers. This approach addresses individual
layers of the solution during each cycle of development.
Benefits of Iterative
Development:
• Maximizes customer satisfaction.
• Adds value to the product or service.
• Enables faster delivery of working software, services or products.
• Leads to continuous improvement (Kaizen).
EXAMPLE
• FOR i ← 1 TO 10
• OUTPUT i
• NEXT i
• This will output numbers 1 to 10 – exactly 10 times.
Shapes of flow chart
Flow chart
• Any QUERIES ??

You might also like