python guide 11 to 12 pdf
python guide 11 to 12 pdf
Introduction to Problem-solving
1. Analyzing the problem: Understand the problem by identifying inputs, outputs, and
requirements.
2. Developing an algorithm: Write step-by-step instructions to solve the problem.
3. Coding: Convert the algorithm into a programming language (Python).
4. Testing: Run the program to verify it produces the expected output.
5. Debugging: Identify and x errors.
Example: Problem: Find the square of a number.
• Oval: Start/End.
• Rectangle: Process.
• Parallelogram: Input/Output.
• Diamond: Decision-making.
Flowchart for Squaring a Number:
mathematica
┌────────────┐
│ Start │
└────┬───────┘
│
┌────▼───────┐
│ Input num │
└────┬───────┘
│
┌────▼─────────────┐
│ square = num ** 2 │
└────┬─────────────┘
│
1 of 17
fi
fi
┌────▼──────────────┐
│ Print square │
└────┬──────────────┘
│
┌────▼───────┐
│ End │
└────────────┘
python
print("Hello, World!")
• Execution Modes:
◦ Interactive Mode: Type commands directly into the Python shell.
◦ Script Mode: Save the code in a le (e.g., program.py) and run it using the
terminal.
• Character Set: A set of valid characters (letters, digits, symbols) used in Python programs.
• Tokens:
python
# Tokens example
x = 5 # Identifier
print(x + 2) # Operator and literal
2 of 17
fi
fi
• r-value: The actual value being assigned (right side of =).
Example:
python
x = 10 # x is the l-value, 10 is the r-value
✅ 6. Data Types
python
x = 10 # int
y = 3.14 # float
z = 3 + 4j # complex
flag = True # boolean
text = "Python" # string
✅ 7. Operators
• Arithmetic: +, -, *, /, //, %, **
• Relational: ==, !=, <, >, <=, >=
• Logical: and, or, not
• Assignment: =, +=, -=, *=, /=
• Identity: is, is not
• Membership: in, not in
Example:
python
x = 10
y = 5
print(x + y) # Arithmetic
print(x > y) # Relational
print(x > 5 and y < 10) # Logical
3 of 17
python
# Type Conversion
x = "10"
y = int(x) # Explicit conversion
print(type(y)) # <class 'int'>
✅ 9. Flow of Control
python
x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is not greater than 5")
python
# For Loop
for i in range(5):
print(i)
# While Loop
x = 1
while x <= 5:
print(x)
x += 1
4 of 17
✅ 12. Strings
python
text = "Python"
print(len(text)) # Length
print(text.upper()) # Uppercase
print(text[0:3]) # Slicing
✅ 13. Lists
python
nums = [1, 2, 3, 4, 5]
nums.append(6)
print(nums)
✅ 14. Tuples
• Immutable sequences.
• Methods: count(), index(), min(), max(), etc.
Example:
python
tpl = (1, 2, 3, 4)
print(tpl[0]) # Indexing
✅ 15. Dictionary
• Key-Value pairs.
• Methods: keys(), values(), items(), get(), update()
Example:
python
person = {"name": "John", "age": 25}
print(person["name"])
5 of 17
• math: sqrt(), ceil(), floor()
• random: randint(), random()
• statistics: mean(), median()
Example:
python
import math
print(math.sqrt(16)) # 4.0
6 of 17
QUESTION AND PRACTICE:—
python
# Input length and breadth
length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
# Calculate area
area = length * breadth
python
num = int(input("Enter a number: "))
if num % 2 == 0:
print(num, "is Even")
else:
print(num, "is Odd")
✅ Program 3: Find the Largest of Three Numbers
python
# Input three numbers
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
python
x = int(input("Enter value of x: "))
y = int(input("Enter value of y: "))
7 of 17
# Swap values
x, y = y, x
print("After swapping:")
print("x =", x)
print("y =", y)
python
num = int(input("Enter a number: "))
python
n = int(input("Enter a positive integer: "))
sum = 0
python
num = int(input("Enter a number: "))
factorial = 1
python
8 of 17
n = int(input("Enter the number of terms: "))
a, b = 0, 1
print("Fibonacci Sequence:")
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
✅ Program 9: Check if a Number is Prime
python
if num > 1:
for i in range(2, num):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num, "is a Prime number")
else:
print(num, "is not a Prime number")
else:
print(num, "is not a Prime number")
✅ Program 10: Print a Pattern
python
rows = int(input("Enter number of rows: "))
python
text = input("Enter a string: ")
reverse = text[::-1]
print("Reversed string:", reverse)
✅ Program 12: Count Vowels in a String
python
9 of 17
text = input("Enter a string: ").lower()
vowels = "aeiou"
count = 0
python
text = input("Enter a string: ").lower()
reverse = text[::-1]
if text == reverse:
print("Palindrome")
else:
print("Not a Palindrome")
✅ Program 14: String Operations
python
text = "Python Programming"
print("Uppercase:", text.upper())
print("Lowercase:", text.lower())
print("Length:", len(text))
print("First 6 characters:", text[:6])
python
nums = [5, 10, 15, 20, 25]
print("Maximum:", max(nums))
print("Minimum:", min(nums))
✅ Program 16: Sum of List Elements
python
nums = [2, 4, 6, 8, 10]
10 of 17
✅ Program 17: Remove Duplicates from a List
python
nums = [1, 2, 2, 3, 4, 4, 5]
unique_nums = list(set(nums))
python
# Creating a tuple
tpl = (10, 20, 30, 40)
print("Tuple:", tpl)
print("First element:", tpl[0])
print("Length:", len(tpl))
print("Sum:", sum(tpl))
💡 5. Dictionary Operations
python
# Creating a dictionary
person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
# Displaying dictionary
print("Dictionary:", person)
print("Name:", person["name"])
print("Age:", person["age"])
✅ Program 20: Count Frequency of Elements in a List
python
nums = [1, 2, 2, 3, 4, 4, 4, 5]
freq = {}
python
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
# Merging dictionaries
merged_dict = {**dict1, **dict2}
print("Merged Dictionary:", merged_dict)
⚙ 6. Python Modules
python
import math
num = 16
print("Square Root:", math.sqrt(num))
print("Power:", math.pow(2, 3))
print("Ceil:", math.ceil(3.2))
print("Floor:", math.floor(3.8))
✅ Program 23: Random Number Generation
python
import random
python
import statistics
print("Mean:", statistics.mean(data))
print("Median:", statistics.median(data))
print("Mode:", statistics.mode(data))
12 of 17
🔥 📄 Practice Questions – Topic-wise
✅ 3. Flow of Control
✅ 4. Iterative Statements
1. Explain the difference between for loop and while loop with examples.
2. Write a program to print the multiplication table of a given number.
3. Write a program to calculate the sum of the rst n natural numbers.
4. Create a pattern printing program using nested loops:
markdown
*
* *
* * *
* * * *
✅ 5. Strings
✅ 6. Lists
✅ 7. Tuples
✅ 8. Dictionaries
✅ 9. Python Modules
1. Write a program using the math module to calculate the square root and power of a
number.
2. Use the random module to generate a random number between 1 and 100.
3. Write a program using the statistics module to nd the mean, median, and mode of
a list of numbers.
4. Simulate the rolling of two dice using the random module.
14 of 17
fi
fi
fi
fi
fi
python
print(5 // 2)
a) 2.5
b) 2
c) 3
d) 1
python
x = 10
y = 5
print(x > y and x < 15)
a) True
b) False
c) Error
d) None
I'll generate a owchart showing the logic to nd the largest of three numbers.
🔹 Algorithm:
🔹 Flowchart:
15 of 17
fl
fi
🔥 2. Flowchart for Calculating the Factorial of a Number
🔹 Algorithm:
🔹 Algorithm:
🔹 Flowchart:
16 of 17
🔥 4. Flowchart for Fibonacci Series
🔹 Algorithm:
17 of 17
fi