Python I Unit Material

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Problem Solving with Python

24CS101

Unit I
Introduction to Mechanical Devices and Computing
Unit I: Introduction to Mechanical Devices and Computing
Evolution of Computers
Mechanistic Devices
Mechanistic devices are tools or systems that use mechanical components to perform a specific
function or achieve a particular goal. These devices typically rely on physical principles, such
as levers, gears, and pulleys, to transmit motion, force, or energy.
1. Clocks and Watches
2. Gearboxes
3. Hydraulic systems
4. Levers and fulcrums
5. Pulley systems
6. Chain drives
7. Belt drives

Mechanistic devices are used in a wide range of applications, including:


1. Industrial machinery
2. Timekeeping devices
3. Musical instruments
4. Toys and puzzles
5. Robotics
6. Automotive systems

Grading Machines
Devices that are used to classify items based on overall quality are termed as grading machines.
These machines are commonly used in various industries to ensure that products meet certain
standards and specifications before they reach the consumer or the next stage of processing.
Grading machines enhance productivity, ensure product quality, and reduce labor costs, making
them essential tools in many industries. These machines can handle large volumes of items
quickly, which is essential for industries with high production rates.
Example: Part graders in manufacturing: Used to grade manufactured parts based on
dimensions, weight, or other specifications to ensure quality control.
Sorters
Devices that are used to sort items based on a specific criteria or parameter are termed as
sorters. Parameters may include size, weight, color, quality, or other properties. They are
designed to provide accurate and consistent sorting or classification based on predefined
criteria. Like grading machines, these machines can also handle large volumes of items quickly,
and reduce labour costs.
Example: Fruit and Vegetable Graders: These machines sort produce by size, weight, color, or
ripeness. For example, apple sorters can sort apples into different categories based on size and
color.

Generations of Computers
First Generation Computers (1940-1956)
• Vacuum tubes were used in circuits.
• These computers are very large in size.
• Programming for this generation was done using machine language.
• They were very expensive and require a large amount of electricity.
• They produce more heat.
• Computers could calculate data in a millisecond.
• Examples: ENIAC and UNIVAC-1.

Second Generation Computers (1957-1963)


• Vacuum tubes were replaced by transistors in circuits.
• These computers were smaller in size.
• They produced less amount of heat.
• They required less amount of electricity.
• These computers used Assembly language.
• These computers could calculate data in a microsecond.
• Examples : IBM 1920, IBM 1401, etc.

Third Generation Computers (1964-1971)


• Transistors were replaced by Integrated Circuits.
• These computers used lesser power and generated lesser heat.
• Operating system were used.
• These were general purpose computers.
• Computers calculate data in a nanosecond.
• High-level languages were introduced.
• Examples : IBM-360 series, CDC 1700
Fourth Generation Computers (1972 onward)
• The integration of thousands and millions of transistors on a small silicon chip.
• High-level languages like C and C++ are used.
• Operating systems like MS-DOS and Windows were introduced.
• The computation speed increased to picoseconds.
• Microprocessors are developed.
• Computers now have become smaller, faster and more reliable.
• Examples: CRAY- 1, Apple, etc.

Fifth Generation Computers (Present and future)


• It is based on the technique of Artificial Intelligence (AI).
• A computer can understand spoken words.
• Currently, scientists are working to increase the processing power of computers.
• They are trying to create a computer with real IQ with the help of advanced
programming and technologies.
• Examples: IBM notebooks

Introduction to programmable calculators


• A programmable calculator allows users to write and execute custom programs to
perform specific calculations or automate repetitive tasks.
• These can be customized to suit complex or specific needs.
• Key Features
 Programmability: Users can create and store custom programs and functions.
 Memory Storage: They have memory to store programs, data, and variables.
 Function Keys: They often have additional function keys to facilitate
programming.
 Display: Typically feature an LCD or LED display for showing results.

Computer hardware & software


• A computer is a programmable device that stores, retrieves, and processes data.
• It requires minimum the parts listed below.
 Processor - Component that executes instructions from the software.
 Memory - Primary storage for data traveling between the storage and CPU.
 Motherboard - Component that connects all components.
 Storage Device - Slower secondary storage that permanently stores data.
Hardware:
• Physical structure that houses a computer's processor, memory, storage,
communication ports and peripheral devices.
• Each of these components have a different purpose, which may be either accepting
inputs, storing data or sending outputs.
Software:
• All parts of a computer that are not strictly physical, such as data, programs,
applications, protocols, etc., are broadly defined as “software.”

Components and functionalities of computer devices:


1. Central Processing Unit (CPU)
• Function: It executes instructions from programs, and controls other hardware
components.
• Components:
• Arithmetic Logic Unit (ALU): Performs arithmetic and logical operations.
• Control Unit (CU): Directs operations of the CPU and coordinates all
activities.
• Registers: Small, fast storage locations within the CPU used to hold data
temporarily.
2. Memory
• Random Access Memory (RAM):
• Function: Temporary storage for data and instructions that the CPU needs while
performing tasks.
• Read-Only Memory (ROM):
• Function: Permanent storage for firmware and system instructions that are not
meant to be altered frequently. It’s non-volatile.

3. Storage
• Hard Disk Drive (HDD):
• Function: A traditional storage device using spinning disks to read/write
data.
• Solid-State Drive (SSD):
• Function: A newer storage device using flash memory. Faster access speeds
and more durable compared to HDDs.

4. Motherboard
• Function: The main circuit board that houses the CPU, memory, and other essential
components.
• Components:
• Chipset: Manages data flow between the processor, memory, and peripherals.
• Slots and Connectors: For additional hardware like RAM, expansion cards,
and storage devices.

5. Power Supply Unit (PSU)


• Function: Converts electrical power from an outlet into usable power for the
computer's internal components.

6. Graphics Processing Unit (GPU)


• Function: Handles rendering of images, videos, and animations.
• It can also perform parallel processing tasks for applications like deep learning.

7. Input Devices
• Function: Devices used to input data into the computer.
• Examples:
• Keyboard: For typing text and commands.
• Mouse: For pointing, clicking, and scrolling.
• Scanner: For digitizing physical documents and images.

8. Output Devices
• Function: Devices used to output data from the computer.
• Examples:
• Monitor: Displays visual output from the computer.
• Printer: Produces physical copies of documents and images.
• Speakers: Output sound.

9. Network Interface Card (NIC)


• Function: Allows the computer to connect to a network, either through a wired Ethernet
connection or a wireless Wi-Fi connection.

10. Cooling System


• Function: Prevents overheating of computer components by dissipating excess heat.
• Components:
• Fans: Circulate air to cool internal components.
• Heat Sinks: Absorb and dissipate heat from the CPU or GPU.

Overview of Networked computing and cloud computing


It involves connecting multiple computers and devices to share resources. It allows computers
to communicate with each other over a network.
Types of Networks:
1. Local Area Network (LAN): A network that connects devices within a limited
area.
2. Wide Area Network (WAN): A network that covers a larger geographical area,
such as connecting multiple offices across cities or countries.
3. Internet: A global network connecting millions of private and public networks.
Network Devices:
1. Router: Directs data packets between different networks.
2. Switch: Connects devices within a LAN and directs data to the correct device.
3. Modem: Converts digital data to analog signals for transmission over telephone
lines and vice versa.
Network Topologies:
1. Star Topology: Devices are connected to a central hub or switch.
2. Bus Topology: All devices are connected to a single central cable.
3. Ring Topology: Devices are connected in a circular fashion.
Security:
1. Firewalls: Protect networks from unauthorized access by filtering incoming and
outgoing traffic.
2. Encryption: Secures data transmitted over networks by converting it into a
code.

Cloud computing
Cloud Computing means storing and accessing the data and programs on remote servers that
are hosted on the internet instead of the computer’s hard drive or local server. Cloud computing
is also referred to as Internet-based computing, it is a technology where the resource is provided
as a service through the Internet to the user. The data that is stored can be files, images,
documents, or any other storable document.
Key Concepts
1. Cloud Service Models:
1. Infrastructure as a Service (IaaS): Provides virtualized computing resources
over the internet.
2. Platform as a Service (PaaS): Offers a platform allowing developers to build,
deploy, and manage applications without worrying about the underlying
infrastructure.
3. Software as a Service (SaaS): Delivers software applications over the internet,
typically via a subscription model.
Example: Microsoft Office 365.
2. Cloud Deployment Models:
1. Public Cloud: Services are provided over the public internet. Examples: AWS,
2. Private Cloud: Services are maintained on a private network and used
exclusively by one organization.
3. Hybrid Cloud: Combines public and private clouds, allowing data and
applications to be shared between them.

Benefits of Cloud computing


1. Scalability: Easily scale resources up or down based on demand.
2. Cost-Efficiency: Pay only for the resources you use, reducing the need for large
capital investments in hardware.
3. Accessibility: Access resources and applications from anywhere with an
internet connection.
4. Disaster Recovery: Cloud providers often offer backup and recovery solutions
to protect data in case of failures.
Security and Compliance of Cloud computing:
1. Data Encryption: Ensures data is protected both in transit and at rest.
2. Identity and Access Management (IAM): Controls who can access cloud
resources and what they can do with them.
3. Compliance: Ensures that cloud services adhere to relevant regulations and
standards.

Data Representation in Computer


Digital systems use digital circuits that can process digital signals which can take either 0 or
1 for binary system.
Advantages of Digital system over Analog system
 Ease of programmability
 Reduction in cost of hardware
 High speed
 High Reliability
 Design is easy
Number System: Different numbering systems are used due to the unique characteristics and
applications of each system.
Different Number Systems:
I. Decimal numbering system
II. Binary numbering system
III. Octal numbering system
IV. Hexa-Decimal numbering system
Decimal Numbering System:
Decimal numbering system is most familiar to humans as it is the standard counting system.
It is called "decimal" because it is based on ten unique digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
Key Features of the Decimal System
• Base-10 (Radix): The system is based on ten, meaning each digit's position represents
a power of ten.
• Digits: There are ten digits (0 through 9) used to represent all numbers.
• Place Value: The value of each digit depends on its position in the number. The
rightmost digit represents 𝟏𝟎𝟎 , the next represents 𝟏𝟎𝟏 , then 𝟏𝟎𝟐 , and so on. This
place value increases by a factor of ten as you move left.

Binary Numbering System


Binary number has a radix of 2. Only two digits are needed, and these are 0 and 1. In binary
system weight is expressed as power of 2.
Key Features
• Base-2: The system is based on two, meaning each digit's position represents a power
of two.
• Digits: The binary system uses two digits, 0 and 1, to represent all numbers.
• Place Value: The value of each digit depends on its position in the number, with the
rightmost digit representing 𝟐𝟎 , the next representing 𝟐𝟏 , then 𝟐𝟐 , and so on. The
place value increases by a factor of two as you move left.
Example: Consider a binary number 1101
1× 𝟐𝟑 +1× 𝟐𝟐 +0× 𝟐𝟏 +1× 𝟐𝟎 = 13 (Decimal)

Octal Numbering System


The octal numbering system, or Radix-8 system, is an important numbering system in
computing. It uses eight unique digits: 0, 1, 2, 3, 4, 5, 6, and 7.
Key Features
• Base-8: The system is based on eight, meaning each digit's position represents a
power of eight.
• Digits: The octal system uses the digits 0 through 7.
• Place Value: The value of each digit depends on its position in the number. The
rightmost digit represents 𝟖𝟎 , the next represents 𝟖𝟏 , then 𝟖𝟐 , and so on. The place
value increases by a factor of eight as you move left.
Example: Consider a octal number 257 (Octal)
2× 𝟖𝟐 +5× 𝟖𝟏 +7× 𝟖𝟎 = 175 (Decimal)

Hexa Decimal Numbering System


It is also known as the base-16 system, is widely used in computing and digital electronics. It
uses sixteen unique symbols to represent values: the digits 0-9 and the letters A-F. The
hexadecimal system provides a more compact and human-readable format.
Key Features
• Base-16: The system is based on sixteen, meaning each digit's position represents a
power of sixteen.
• Digits: The hexadecimal system uses the digits 0-9 and the letters A-F, where A
represents 10, B represents 11, C represents 12, D represents 13, E represents 14, and
F represents 15.
• Place Value: The value of each digit depends on its position in the number. The
rightmost digit represents 𝟏𝟔𝟎 , the next represents𝟏𝟔𝟏 , then𝟏𝟔𝟐 , and so on. The place
value increases by a factor of sixteen as you move left.

Number Conversions
• Binary to Decimal Conversion: To convert a binary number to a decimal number, sum
the products of each binary digit and its corresponding power of 2.
• Decimal to Binary Conversion: To convert a decimal number to a binary number,
repeatedly divide the number by 2 and record the remainders. Present the remainders
in reverse order.
• Binary to Octal Conversion: To convert a binary number to an octal number, group
the binary digits in sets of three, starting from the least significant digit. Then convert
each group to its octal equivalent.
• Octal to Binary Conversion: To convert an octal number to binary, convert each octal
digit to a three-digit binary number.
• Binary to Hexadecimal Conversion: To convert a binary number to a hexadecimal
number, group the binary digits in sets of four, starting from the least significant digit.
Then convert each group to its hexadecimal equivalent.
• Hexadecimal to Binary Conversion: To convert a hexadecimal number to binary,
convert each hexadecimal digit to a four-digit binary number.
• Decimal to Octal Conversion: To convert a decimal number to an octal number,
repeatedly divide the number by 8 and record the remainders. Present the remainders
in reverse order.
• Octal to Decimal Conversion: To convert an octal number to a decimal number, sum
the products of each octal digit and its corresponding power of 8.
• Decimal to Hexadecimal Conversion: To convert a decimal number to a hexadecimal
number, repeatedly divide the number by 16 and record the remainders. Present the
remainders in reverse order.
• Hexadecimal to Decimal Conversion: To convert a hexadecimal number to a decimal
number, sum the products of each hexadecimal digit and its corresponding power of 16.

ASCII Character Encoding


1. ASCII stands for American Standard Code for Information Interchange. It is a
character encoding standard. Character Set: ASCII consists of 128 characters, represented
by a 7-bit binary number. This includes:
Control Characters (0-31): Non-printable characters.
• Printable Characters (32-126):
• Space (32): The space character.
• Punctuation (33-47, 58-64, 91-96, 123-126): Characters like !, @, [, ],
etc.
• Digits (48-57): 0 to 9.
• Uppercase Letters (65-90): A to Z.
• Lowercase Letters (97-122): a to z.

Encoding: Each character is mapped to a unique integer value. For example:


• The letter "A" is represented by the decimal number 65.
• The letter "a" is represented by the decimal number 97.

Extended ASCII: An extension of the standard ASCII that uses 8 bits (1 byte) to represent 256
characters.
• The additional characters (128-255) include special symbols, and additional control
characters.
Usage
• Communication: ASCII is widely used in data transmission protocols.
• Programming: Used in languages and systems that require text representation, such as
C, Python, and many others.
• File Formats: Text files and email headers, use ASCII encoding.

Introduction to Operating Systems


An operating system (OS) serves as an intermediary between computer hardware and the end-
user. The basic functionalities of an operating system include:
1. Process Management:
• The OS manages processes in a system, which includes process creation, scheduling,
termination, and synchronization.
2. Memory Management:
• The OS handles memory allocation and deallocation for processes. It keeps track of
each byte in a computer's memory and manages the sharing and protection of memory
space between multiple processes.
3. File System Management:
• The OS manages files on a disk, including their creation, deletion, reading, and writing.
It organizes files in directories for efficient access and management.
4. Device Management:
• The OS manages device communication through drivers, which act as translators
between the hardware and software.
5. Security and Access Control:
• The OS provides security features to protect data and system resources from
unauthorized access. It includes user authentication, data encryption, to control access
to files and devices
6. User Interface:
• The OS provides a user interface, either through a command-line interface (CLI) or a
graphical user interface (GUI), to execute commands.
7. Resource Allocation and Management:
• The OS allocates system resources such as CPU time, memory, and input/output
devices to various programs and users efficiently.
8. System Performance Monitoring and Optimization:
• The OS monitors system performance and optimizes resource usage to ensure efficient
operation. It includes tools for monitoring CPU usage, memory consumption, and disk
usage.

Types of Operating System


1. Batch Operating Systems
• Description: Processes batches of jobs without user interaction. Jobs with similar
needs are batched together and executed sequentially.
• Examples: IBM's OS/360.
2. Time-Sharing Operating Systems
• Description: Allows multiple users to share system resources simultaneously. It uses
time-sharing techniques to switch between users' jobs quickly.
• Examples: UNIX
3. Distributed Operating Systems
• Description: Manages a group of independent computers and makes them appear as a
single computer. The system distributes tasks across multiple machines.
• Examples: Microsoft Azure.
4. Network Operating Systems
• Description: Provides networking capabilities and allows computers to communicate
and share resources over a network.
• Examples: Microsoft Windows Server.
5. Real-Time Operating Systems (RTOS)
• Description: Designed to process data in real-time with minimal delay. They are used
in systems that require a high degree of timing accuracy and reliability.
• Examples: FreeRTOS.
6. Embedded Operating Systems
• Description: Specialized OS designed for embedded systems, which are dedicated to
specific tasks.
• Examples: iOS (for Apple devices).
7. Mobile Operating Systems
• Description: Designed specifically for mobile devices such as smartphones and tablets.
• Examples: Android, iOS.
8. Multitasking/Multiprogramming Operating Systems
• Description: Allow multiple programs to run simultaneously by managing their
execution. Multitasking can be preemptive or cooperative.
• Examples: Windows, macOS, Linux.
9. Single-User and Multi-User Operating Systems
• Single-User OS: Designed for one user to access the system at a time.
• Multi-User OS: Allows multiple users to access the system concurrently, providing
resources and facilities to each user.
• Examples: Single-User (MS-DOS), Multi-User (Unix, Linux).
10. Desktop Operating Systems
• Description: Designed for personal computers (PCs) with a graphical user interface
(GUI) for everyday tasks.
• Examples: Windows, macOS
11. Server Operating Systems
• Description: Designed to run on servers and provide services to client machines over a
network.
• Examples: Windows Server, Ubuntu Server
12. Mainframe Operating Systems
• Description: Built for large-scale computing environments, supporting thousands of
users and massive transactions.
• Examples: z/OS, IBM's VM.

Computer languages
Machine languages and high-level languages are two categories of programming languages
Differ significantly in their level of abstraction and how they interact with hardware.
Machine Languages
Machine language is the lowest-level programming language, consisting of binary code that is
directly executed by a computer's central processing unit (CPU).
Characteristics:
1. Binary Code: Consists of 0’s and 1’s, representing on and off states of electrical
signals.
2. Hardware-Specific: Code written for one type of CPU will not work on another
without modification.
3. Fast Execution: Since machine code is executed directly by the hardware, it is
very efficient in terms of execution speed.
4. Difficult to Write and Read: because it lacks any symbolic representation and is
purely numerical.
High Level Language
High-level languages (HLLs) are programming languages that are more abstract and easier for
humans to read and write. They are closer to human languages and further from machine code.
Characteristics:
1. Abstraction: High-level languages abstract away hardware details, allowing developers
to focus on logic and functionality rather than hardware specifics.
2. Syntax: They use natural language elements, making them easier to learn and
understand.
3. Portability: High-level code can often run on multiple types of hardware with minimal
modification, as long as the appropriate compilers or interpreters are available.
4. Ease of Use: They provide features like variables, data types, control structures, and
error-handling, making it easier to write, debug, and maintain code.

Problem-Solving Strategies
• Problem-solving in programming involves a systematic approach to finding
solutions to challenges or tasks.
• Some common strategies and steps to effectively solve problems in programming:
Identifying and Defining Problems:
• Identifying Problems: The first step is to recognize that a problem exists. This involves
observing and understanding the current situation, recognizing any discrepancies
between the desired and actual outcomes, and acknowledging that a problem needs to
be solved.
• Defining Problems: Once identified, it's crucial to clearly define the problem. This
includes specifying the problem's scope, understanding the relevant details, and
determining the criteria for a successful solution. A well-defined problem statement
helps focus efforts and resources on finding an effective solution.
Breaking Down Problems into Manageable Parts with Logical Thinking
• Breaking Down Problems: Large and complex problems can be overwhelming. By
decomposing them into smaller, more manageable components, you can tackle each
part individually. This makes it easier to develop solutions and manage the problem-
solving process.
• Logical Thinking: Using logical reasoning is essential in problem-solving. It involves
analyzing the problem, identifying cause-and-effect relationships, and systematically
working through each part. Logical thinking helps in creating structured approaches,
ensuring that solutions are based on sound reasoning and are systematically developed.

Common problem-solving techniques


Methodologies and approaches used to tackle a wide range of problems systematically.
1. Divide and Conquer
Break a problem into smaller, more manageable subproblems, solve each one
independently, and combine their solutions to solve the original problem.
Examples: Merge sort, quicksort.
2. Dynamic Programming
Solve complex problems by breaking them down into simpler subproblems and storing
the results of these subproblems to avoid redundant computations.
Examples: Fibonacci sequence.
3. Greedy Algorithms
Make a series of choices, each of which is the best at the moment, hoping to find a
global optimum.
Examples: Dijkstra's algorithm.
4. Backtracking
Try out different solutions and backtrack as soon as you realize that a solution path
won't work. It's often used for constraint satisfaction problems.
Examples: N-Queens problem, Sudoku solver.
5. Brute Force
Try all possible solutions to find the best one. It’s straightforward but often inefficient.
Examples: Checking all possible combinations, password cracking.
6. Heuristic Methods
Uses experience-based techniques for problem-solving, learning, and discovery.
Examples: A* search algorithm.
7. Pattern Recognition
Identify patterns or regularities in data to make predictions or simplify problems.
Examples: Recognizing recurring patterns in data analysis.
8. Simulation
Model the problem in a simulated environment to observe and analyze different
scenarios and outcomes.
Examples: Traffic flow simulations.
9. Analogy
Draw parallels between a new problem and a problem you've solved in the past. Use
the solution of the known problem to solve the new one.
Examples: Applying the strategy of one game to another similar game.
10. Reduction
Transform the problem into a known problem for which solutions already exist.
Examples: Reducing the traveling salesman problem to a graph traversal problem.

Program Design Tools


Program design tools are software applications and techniques used by developers and
engineers to plan, design, and develop software applications. Examples: Raptor for flowchart
development and Scratch for algorithm design.
Flowchart
A flowchart is a diagrammatic representation of an algorithm. Flowchart is most widely used
graphical representation of procedural design workflows. It makes use of symbols which are
connected among them to indicate the flow of information and processing.
Raptor allows users to write and execute programs using flowcharts. It is a flowchart-based
programming environment, designed specifically to help visualize algorithms. Symbols used
in Raptor software for flowchart design are described below:
1. Assignment
The assignment symbol is used to change the value of a variable. The
right-hand side of the assignment is evaluated, and the resulting value
is placed in the variable on the left-hand side.

2. Call
The call symbol is used to invoke procedures such as graphics routines
and other instructor-provided procedures. The call symbol is also used
to run sub charts included in a Raptor program.

3. Input
The input symbol is used to ask the user for a number or string while the
flowchart is executing. When an input symbol is executed, the user will
be prompted with a dialog to enter a value that can be interpreted as
either a number or string, depending on what the user types.

4. Output
The output symbol is used to either write a number or text to the Master
Console window.
5. Selection
The selection structure is used for decision making. The programmer
enters in the diamond an expression that evaluates to Yes (True) or No
(False). Such expressions are formally referred to as Boolean
expressions. Based on the result of the expression in the diamond,
control of the program will branch either left (Yes, or True) or right (No,
or False).

6. Loop Control
The loop structure is used to repeat a sequence of symbols until a certain
condition is met. When execution reaches the bottom of the loop, it starts
over again at the top. The loop is exited when the diamond symbol is
executed and the Boolean expression in the diamond evaluates to Yes
(True).

Example flowchart to check perform LCM of two given numbers:


Algorithms
An algorithm is a step-by-step procedure for solving a problem or accomplishing a task. It is a
set of finite rules or instructions to be followed in calculations or other problem-solving
operations.
Characteristics of an Algorithm
1. Clear and Unambiguous: The algorithm should be unambiguous. Each of its steps
should be clear in all aspects and must lead to only one meaning.
2. Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined
inputs.
3. Well-Defined Outputs: The algorithm must clearly define what output will be yielded
and it should be well-defined as well. It should produce at least 1 output.
4. Finiteness: The algorithm must be finite, i.e. it should terminate after a finite time.
5. Feasible: The algorithm must be simple, generic, and practical, such that it can be
executed with the available resources.
6. Language Independent: The Algorithm must be just plain instructions that can be
implemented in any language.
7. Effectiveness: An algorithm must be developed by using very basic, simple, and
feasible operations so that one can trace it out by using just paper and pencil.

Scratch is a visual programming language that allows to create interactive stories, games and
animations. Scratch was created by the Lifelong Kindergarten group at MIT Media lab.
Elements of Scratch: There are four main elements of Scratch: the stage, the sprites, the script
and the programming palette. These elements can be compared to a play.

1) Stage – similar to the stage in a play. This is where everything will take place.
2) Sprites – are the actors or main characters of the project. Sprites are programmed to do
something in Scratch.
3) Script – tells the actors what to say or do. Each sprite is programmed with a script.
4) Programming palette – elements used to program the sprite to do or say something. Sprites
must be programmed to carry out every function you want them to perform.

Example Scratch Script to check whether entered number is prime or not.

You might also like