Bilkul! Neeche Lab 1 se Lab 15 tak Python Programming course ke tamam labs diye gaye hain Roman Urdu mein โ har lab mein:
- Short explanation
- Example code
- Student exercises
โ Lab 1: Introduction to Python Programming
๐ Explanation:
Python aik simple aur powerful programming language hai. Yeh beginners ke liye best hai.
๐งช Example Code:
print("Hello, Python!")
๐ Exercises:
- Apna naam aur age print karo.
- Python ka version check karo using
import sys; print(sys.version)
.
โ Lab 2: Basic Input/Output & String Operations
๐ Explanation:
input()
user se data leta hai.print()
output dikhata hai.- Strings mein text store hota hai.
๐งช Example Code:
name = input("Apna naam likho: ")
print("Welcome " + name)
๐ Exercises:
- User se naam aur city lo aur welcome message do.
- Ek string ka reverse print karo.
- String ko upper aur lower case mein convert karo.
โ Lab 3: Boolean Logic & Logical Operators
๐ Explanation:
Boolean values sirf True
ya False
hote hain. Logical operators: and
, or
, not
.
๐งช Example Code:
a = 5
b = 10
print(a < 10 and b > 5)
๐ Exercises:
- Do numbers lo aur check karo dono positive hain ya nahi.
- Age aur marks ki condition se eligibility check karo.
โ Lab 4: Dates and Time
๐ Explanation:
datetime
module se hum date aur time ke sath kaam karte hain.
๐งช Example Code:
import datetime
now = datetime.datetime.now()
print("Aaj ki date:", now)
๐ Exercises:
- Current date aur time print karo.
- User ka birth year lo aur uski age calculate karo.
โ Lab 5: Conditional Statements
๐ Explanation:
if
, elif
, else
ka use conditions check karne ke liye hota hai.
๐งช Example Code:
age = int(input("Age daalo: "))
if age >= 18:
print("Adult ho")
else:
print("Underage ho")
๐ Exercises:
- Positive/negative/zero number check karo.
- Student ka grade calculate karo based on marks.
โ Lab 6: Loops
๐ Explanation:
Loops code ko repeat karne ke liye use hotay hain.
๐งช Example Code:
for i in range(1, 6):
print("Number:", i)
๐ Exercises:
- 1 se 10 tak numbers print karo.
- 2 ka table print karo.
- While loop se countdown likho.
โ Lab 7: Functions
๐ Explanation:
Function aik block hota hai jo bar bar use kiya ja sakta hai.
๐งช Example Code:
def greet(name):
print("Hello, " + name)
greet("Ali")
๐ Exercises:
- Function banao jo square return kare.
- Function banao jo 2 numbers ka sum de.
โ Lab 8: Lists, Indexing, and Slicing
๐ Explanation:
List multiple items store karti hai. Indexing aur slicing se data access karte hain.
๐งช Example Code:
fruits = ["apple", "banana", "mango"]
print(fruits[1])
print(fruits[0:2])
๐ Exercises:
- List banao 5 items ke sath.
- Last item print karo.
- List mein se even numbers dhoondo.
โ Lab 9: Numerical Operations
๐ Explanation:
Math operations like + - * /
, aur math
module ka use hota hai.
๐งช Example Code:
import math
print(math.sqrt(16))
๐ Exercises:
- Average calculate karo do numbers ka.
- Math module se factorial aur power calculate karo.
โ Lab 10: File Handling
๐ Explanation:
Files read ("r"
) aur write ("w"
) modes mein open hoti hain.
๐งช Example Code:
file = open("data.txt", "w")
file.write("Hello, file!")
file.close()
๐ Exercises:
- Ek file create karo aur usme naam likho.
- File read karo aur output dikhayo.
โ Lab 11: Object-Oriented Programming (OOP)
๐ Explanation:
OOP mein hum class aur objects ka use karte hain.
๐งช Example Code:
class Student:
def __init__(self, name):
self.name = name
def greet(self):
print("Hello " + self.name)
s1 = Student("Ahmed")
s1.greet()
๐ Exercises:
- Class banao Car ka jisme model aur year ho.
- Method add karo jo car ka info print kare.
โ Lab 12: Dictionaries and Tuples
๐ Explanation:
- Dictionary key-value pair store karta hai.
- Tuple aik fixed (immutable) list hoti hai.
๐งช Example Code:
student = {"name": "Ali", "age": 21}
print(student["name"])
point = (10, 20)
print(point[0])
๐ Exercises:
- Dictionary banao kisi student ki detail ke sath.
- Tuple banao aur uska sum karo.
โ Lab 13: Data Visualization (Matplotlib)
๐ Explanation:
Graphs aur charts ke liye matplotlib
use karte hain.
๐งช Example Code:
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [2, 4, 1]
plt.plot(x, y)
plt.title("Simple Graph")
plt.show()
๐ Exercises:
- Bar chart banao 3 fruits ke prices ka.
- Pie chart banao marks distribution ka.
โ Lab 14: Computational Problem Solving
๐ Explanation:
Yeh lab logic aur algorithm building pe based hai.
๐งช Example Code (Fibonacci):
n = int(input("Kitne numbers chahiye Fibonacci mein? "))
a, b = 0, 1
for i in range(n):
print(a, end=" ")
a, b = b, a + b
๐ Exercises:
- Prime number check karo.
- Factorial find karo.
- String ke vowels count karo.
- Even numbers list mein se print karo.
โ Lab 15: Error Handling and Debugging
๐ Explanation:
Errors ko handle karne ke liye try-except
use hota hai.
๐งช Example Code:
try:
num = int(input("Ek number do: "))
print(10 / num)
except ZeroDivisionError:
print("Zero se divide nahi kar sakte!")
except ValueError:
print("Sahi number do!")
๐ Exercises:
- Division ka program banao jisme user galat input de to handle ho.
- File read karte waqt error handle karo agar file na mile.