0% found this document useful (0 votes)
2 views18 pages

Problem Solving and Computer Programming

Uploaded by

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

Problem Solving and Computer Programming

Uploaded by

sakila
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Problem Solving and Computer Programming

UNIT II

1. Conceptual Introduction to Computer Science

Definition

Computer Science is the study of computers, computational systems, and the methods used to
solve problems using software and hardware.

Simple Definition

Computer Science is the field of study that teaches us how computers work and how to
develop programs to solve real-world problems.

Explanation

Computer Science involves:

 Designing algorithms

 Writing computer programs

 Developing software

 Managing databases

 Creating websites and mobile applications

 Artificial Intelligence

 Cyber Security

 Computer Networks

Real-Life Example

When you use an ATM, book a train ticket online, shop on Amazon, or use Google Maps,
Computer Science makes these services possible.

Applications

 Banking

 Healthcare

 Education
 Artificial Intelligence

 Robotics

 Gaming

 Mobile Applications

2. Algorithms

Definition

An algorithm is a finite sequence of well-defined instructions used to solve a problem or


complete a task.

Simple Definition

An algorithm is a step-by-step procedure for solving a problem.

Characteristics of an Algorithm

1. Input

2. Output

3. Definiteness (clear steps)

4. Finiteness (must end)

5. Effectiveness (each step should be simple)

Example

Algorithm to Find the Sum of Two Numbers

Step 1: Start

Step 2: Read two numbers A and B

Step 3: Calculate Sum = A + B

Step 4: Display Sum

Step 5: Stop

Real-Life Example
Making tea is an algorithm.

1. Boil water.

2. Add tea powder.

3. Add milk.

4. Add sugar.

5. Stir well.

6. Serve.

3. Modern Computer Systems

Definition

A modern computer system is an electronic system that consists of hardware and software
working together to process data into useful information.

Components

 Hardware

 Software

 Users

 Data

Real-Life Example

A laptop used by a student includes:

 Keyboard

 CPU

 Monitor

 Windows Operating System

 MS Word

All these together form a computer system.


4. Hardware Architecture

Definition

Hardware architecture refers to the physical components of a computer and the way they are
connected to work together.

Main Components

Input Unit

Definition

Accepts data from users.

Examples

 Keyboard

 Mouse

 Scanner

 Microphone

CPU (Central Processing Unit)

Definition

The CPU is called the brain of the computer because it processes instructions and controls all
operations.

Functions

 Performs calculations

 Executes programs

 Controls computer activities

Example

When you open MS Word, the CPU processes your request.


Memory Unit

Definition

Stores data and instructions.

Types

 RAM (Temporary)

 ROM (Permanent)

Example

While editing a document, RAM temporarily stores your work.

Output Unit

Definition

Displays the processed information.

Examples

 Monitor

 Printer

 Speaker

Storage Devices

Definition

Store data permanently.

Examples

 Hard Disk

 SSD

 Pen Drive

 Memory Card
5. Data Representation in Computers

Definition

Data representation is the method by which computers store and process information using
binary digits (0 and 1).

Why Binary?

Computers understand only two electronic states:

 ON = 1

 OFF = 0

Therefore, all information is converted into binary.

Examples

Character A

ASCII Value = 65

Binary = 01000001

Number

25

Binary = 11001

Real-Life Example

When you save a photo or video, the computer stores it internally as millions of binary digits.

6. Software

Definition

Software is a collection of programs that instructs the computer to perform specific tasks.

Types

System Software
Controls hardware.

Examples

 Windows

 Linux

 Android

Application Software

Used for user-specific tasks.

Examples

 MS Word

 Chrome

 VLC

Real-Life Example

Without Windows, MS Word cannot run.

7. Operating System

Definition

An Operating System (OS) is system software that manages computer hardware and software
resources and acts as an interface between the user and the computer.

Functions

 Process Management

 Memory Management

 File Management

 Device Management

 Security

Examples
 Windows

 Linux

 macOS

 Android

Real-Life Example

When you turn on your laptop, Windows loads first and allows you to open applications.

8. Installing Python

Definition

Installing Python means setting up the Python programming language on a computer so that
programs can be written and executed.

Steps

1. Download Python.

2. Install Python.

3. Select Add Python to PATH.

4. Verify installation.

5. Open IDLE or VS Code.

Example

print("Hello World")

Output

Hello World

9. Basic Python Syntax

Definition

Python syntax is the set of rules used to write Python programs correctly.
Rules

 Indentation is important.

 Statements are case-sensitive.

 Variables do not require declaration.

 Comments begin with #

Example

print("Welcome")

10. Interactive Shell

Definition

The Interactive Shell is the Python environment where statements are executed immediately after
typing.

Features

 Executes one line at a time

 Useful for testing programs

 Good for beginners

Example

>>> 20+30

50

11. Editing, Saving and Running a Script

Editing

Writing or modifying Python code.

Example

print("Python")
Saving

Store the program with .py extension.

Example

[Link]

Running

Execute the saved Python file.

Example

python [Link]

Output

Python

12. Data Types

Definition

A data type specifies the type of value stored in a variable.

Types

Data Type Example

int 25

float 12.5

str "Python"

bool True

Example

age = 20

name = "Ravi"
marks = 95.5

passed = True

Variables

A variable is a named memory location used to store data in a computer program. The
value stored in a variable can be used, modified, or replaced during program execution.

Why Do We Need Variables?

Variables help programmers:

 Store data temporarily.

 Reuse values multiple times.

 Perform calculations.

 Reduce code repetition.

 Make programs easier to read and modify.

Without variables, every value would need to be written repeatedly, making programs
difficult to manage.

In Python, variables are created automatically when a value is assigned. Unlike some
programming languages, Python does not require declaring the variable type before using
it.

Python identifies the data type based on the assigned value.

For example,

name = "Rahul"
age = 19
marks = 92.5

Here,

 name stores a string.

 age stores an integer.

 marks stores a floating-point number.


Rules for Naming Variables

 Must begin with a letter or underscore (_).

 Cannot begin with a number.

 Cannot contain spaces.

 Cannot use Python keywords.

Valid Variables

student_name
age
_marks
total1

Invalid Variables

1name
student name
class

Example Program

name = "Anitha"
age = 18
department = "CSE"

print(name)
print(age)
print(department)

Output

Anitha
18
CSE

Real-Life Example

Think of a student ID card.

The student's name, roll number, and department are stored on the ID card.

Similarly,
name = "Anitha"
roll_no = 101
department = "CSE"

Each variable stores one piece of information.

Applications

Variables are used to

 Store student information

 Store employee salaries

 Calculate marks

 Store bank balances

 Store product prices

Almost every Python program uses variables.

Advantages

 Makes programs readable.

 Avoids repetition.

 Simplifies calculations.

 Easy to update values.

 Improves program maintenance.

14. Assignment Statement

Definition

Assignment is the process of storing a value in a variable using the = operator.

Example

x = 10

y = 20

sum = x + y
15. Immutable Variables

Definition

Immutable objects cannot be modified after they are created. If their value changes, a new object
is created instead of modifying the existing one.

Immutable Data Types

 int

 float

 string

 tuple

 bool

Example

x = 10

x = 20

Here, the value 10 is not modified. Instead, Python creates a new object with the value 20 and
makes x refer to it.

Real-Life Example

A printed certificate cannot be edited directly. To make changes, a new certificate is printed.
Similarly, immutable objects are not modified; new objects are created.

16. Numerical Types

Definition

Numerical data types are used to store numeric values.

Types

Integer (int)

Whole numbers
Example

a = 50

Float

Decimal numbers

Example

price = 45.75

Complex

Contains real and imaginary parts

Example

z = 2 + 3j

17. Arithmetic Operators

Definition

Arithmetic operators perform mathematical calculations.

Operator Meaning Example

+ Addition 10+5

- Subtraction 10-5

* Multiplication 10*5

/ Division 10/5

// Floor Division 10//3

% Modulus 10%3

** Exponent 2**3

Example
a = 20

b=6

print(a+b)

print(a-b)

print(a*b)

print(a/b)

18. Expressions

Definition

An expression is a combination of variables, constants, and operators that produces a value.

Example

total = a + b * c

19. Comments

Definition

Comments are non-executable statements used to explain the program.

Types

Single-line

# Calculate sum

Multi-line

'''

This program

adds two numbers

'''
Importance

 Improves readability

 Makes maintenance easier

 Helps other programmers understand the code

20. Understanding Error Messages

Definition

An error message is displayed by Python when a program contains mistakes that prevent it from
executing correctly.

Types of Errors

Syntax Error

Occurs when Python rules are violated.

print("Hello"

Name Error

Occurs when an undefined variable is used.

print(age)

Type Error

Occurs when incompatible data types are used together.

"10" + 20

Zero Division Error

Occurs when dividing a number by zero.

10/0
Real-Life Example

Suppose you type the wrong password while logging into your email account. The system
immediately displays an error message indicating that the password is incorrect. Similarly,
Python displays error messages to help programmers identify and correct mistakes in their code.

This expanded content follows the same Definition → Explanation → Example → Real-life
Example → Applications/Key Points approach, making it ideal for teaching introductory
Python programming to first-year students.

You might also like