CS NOTES
CS NOTES
1. Problem Solving
Definition: Problem-solving is the process of designing, implementing, and testing
solutions to computational problems.
Problem-Solving Steps:
1. Understanding the problem
2. Analyzing requirements
3. Designing a solution (Algorithm, Flowchart, or Pseudocode)
4. Implementing the solution (Writing Code)
5. Testing and Debugging
6. Optimization and Documentation
2. Python Basics
Python is an interpreted, high-level, dynamically typed programming language.
Key Features:
o Easy to learn
o Supports multiple paradigms (Procedural, Object-Oriented, Functional)
o Extensive libraries
x = 10 # int
y = 3.14 # float
z = "Hello" # str
lst = [1, 2, 3] # list
d = {"a": 1, "b": 2} # dictionary
4. Operators in Python
Arithmetic Operators: +, -, *, /, //, %, **
Comparison Operators: ==, !=, >, <, >=, <=
Logical Operators: and, or, not
Bitwise Operators: &, |, ^, ~, <<, >>
Assignment Operators: =, +=, -=, *=, /=, //=, %=, **=
x = 5
y = 2
print(x + y) # Addition
print(x ** y) # Exponentiation
Output:
7
25
5. Expressions in Python
An expression is a combination of variables, operators, and values that produce
a result.
result = (10 + 5) * 2
print(result)
Output:
30
6. Errors in Python
Syntax Error: Incorrect Python syntax (e.g., missing colon)
Runtime Error: Errors that occur during execution (e.g., division by zero)
Logical Error: The program runs but produces incorrect results
try:
print(10 / 0) # ZeroDivisionError
except ZeroDivisionError:
print("Cannot divide by zero!")
Output:
8. Conditional Statements
Used for decision-making in Python.
x = 10
y = 20
if x > y:
print("x is greater")
elif x < y:
print("y is greater")
else:
print("x and y are equal")
Output:
y is greater
9. Looping Statements
For Loop
for i in range(5):
print(i)
Output:
0
1
2
3
4
While Loop
x = 5
while x > 0:
print(x)
x -= 1
Output:
5
4
3
2
1
print(numbers)
Output:
[10, 3, 2, 4]
Output:
3
1
3
Output:
Output:
HELLO WORLD
hello world
hello Python
['hello', 'world']