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

CS NOTES

The document provides detailed notes on Class 11 Computer Science, covering problem-solving steps, Python basics, data types, operators, expressions, errors, control flow, conditional statements, looping, and data structures like lists, tuples, dictionaries, and strings. It includes examples and outputs for each concept to illustrate their usage in Python. The notes serve as a comprehensive guide for understanding fundamental programming concepts and Python syntax.

Uploaded by

Jaipreet Singh
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)
5 views5 pages

CS NOTES

The document provides detailed notes on Class 11 Computer Science, covering problem-solving steps, Python basics, data types, operators, expressions, errors, control flow, conditional statements, looping, and data structures like lists, tuples, dictionaries, and strings. It includes examples and outputs for each concept to illustrate their usage in Python. The notes serve as a comprehensive guide for understanding fundamental programming concepts and Python syntax.

Uploaded by

Jaipreet Singh
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
You are on page 1/ 5

Class 11 Computer Science – Unit 2 Detailed 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

3. Python Data Types


 Python has several built-in data types:
o Numeric Types: int, float, complex
o Sequence Types: list, tuple, range
o Text Type: str
o Mapping Type: dict
o Set Types: set, frozenset
o Boolean Type: bool
o Binary Types: bytes, bytearray, memoryview

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:

Cannot divide by zero!


7. Flow of Control
 Python follows a sequential flow but allows control using:
o Conditional Statements (if, elif, else)
o Looping (for, while)
o Jump Statements (break, continue, pass)

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

10. Lists in Python (Mutable)


numbers = [3, 1, 4, 2]

numbers.append(5) # Adds 5 to the end of the list


numbers.insert(1, 10) # Inserts 10 at index 1
numbers.pop() # Removes the last element
numbers.remove(1) # Removes the first occurrence of 1
numbers.sort() # Sorts the list in ascending order
numbers.reverse() # Reverses the list

print(numbers)

Output:

[10, 3, 2, 4]

11. Tuples in Python (Immutable)


tuple1 = (1, 2, 3, 4, 5)
print(tuple1[2]) # Accessing element at index 2
print(tuple1.count(3)) # Counts occurrences of 3
print(tuple1.index(4)) # Returns index of first occurrence of 4

Output:

3
1
3

12. Dictionary in Python (Mutable)


data = {"name": "Alice", "age": 25, "city": "New York"}

data["age"] = 26 # Modifies value of key 'age'


data["country"] = "USA" # Adds a new key-value pair
print(data.keys()) # Returns all keys
print(data.values()) # Returns all values
print(data.items()) # Returns all key-value pairs as tuples

Output:

dict_keys(['name', 'age', 'city', 'country'])


dict_values(['Alice', 26, 'New York', 'USA'])
dict_items([('name', 'Alice'), ('age', 26), ('city', 'New York'),
('country', 'USA')])
13. Strings in Python (Immutable)
s = "hello world"
print(s.upper()) # Converts to uppercase
print(s.lower()) # Converts to lowercase
print(s.replace("world", "Python")) # Replaces 'world' with 'Python'
print(s.split()) # Splits string into a list by whitespace

Output:

HELLO WORLD
hello world
hello Python
['hello', 'world']

You might also like