← Back to Programming Skills Checklist
SD Jain College FYBCA (SEM-2)¶
204 - Programming Skills Using Python¶
Practical Journal Programs¶
Program 1: Mathematical Operations on Two Numbers¶
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
if b != 0:
print("Division:", a / b)
print("Modulus:", a % b)
else:
print("Division: Not possible (division by zero)")
print("Modulus: Not possible (division by zero)")
Program 2: Dictionary Operations with Roll Numbers¶
students = {101: "Aarav", 102: "Diya", 103: "Krish"}
students[104] = "Mira"
print("Using get() for roll 102:", students.get(102))
removed_value = students.pop(101)
print("Removed:", removed_value)
print("Final dictionary:", students)
Program 3: Sum of Positive Numbers Until 0¶
total = 0
while True:
n = int(input("Enter number (0 to stop): "))
if n == 0:
break
if n < 0:
continue
total += n
print("Sum of positive numbers:", total)
Program 4: NumPy Array Addition and Mean¶
import numpy as np
arr1 = np.array([10, 20, 30, 40, 50])
arr2 = np.array([1, 2, 3, 4, 5])
result = arr1 + arr2
mean_value = np.mean(result)
print("Array 1:", arr1)
print("Array 2:", arr2)
print("Addition:", result)
print("Mean of result:", mean_value)
Program 5: Find Length of List Without len()¶
def find_length(items):
count = 0
for _ in items:
count += 1
return count
data = [5, 10, 15, 20, 25]
print("List:", data)
print("Length:", find_length(data))
Program 6: Nested Dictionary Access¶
student = {
"roll_no": 201,
"name": "Riya",
"marks": {
"python": 88,
"sql": 81
}
}
print("Python marks:", student["marks"]["python"])
Program 7: Character Type Counter in Sentence¶
text = input("Enter a sentence: ")
upper_count = 0
lower_count = 0
digit_count = 0
space_count = 0
special_count = 0
for ch in text:
if ch.isupper():
upper_count += 1
elif ch.islower():
lower_count += 1
elif ch.isdigit():
digit_count += 1
elif ch.isspace():
space_count += 1
else:
special_count += 1
print("Uppercase:", upper_count)
print("Lowercase:", lower_count)
print("Digits:", digit_count)
print("Spaces:", space_count)
print("Special Characters:", special_count)
Program 8: Largest Number in NumPy Array¶
import numpy as np
arr = np.array([12, 45, 7, 89, 34, 90, 56])
print("Array:", arr)
print("Largest number:", np.max(arr))
Program 9: CSV Reader - Employee Data Analysis¶
Create employee_data.csv:
EmployeeID,Name,Department,Salary
1,Amit,Engineering,50000
2,Neha,HR,42000
3,Rahul,Engineering,60000
4,Pooja,Finance,45000
5,Karan,Engineering,55000
Python script:
import csv
total_salary = 0
eng_salary_total = 0
eng_count = 0
with open("employee_data.csv", "r", newline="") as file:
reader = csv.reader(file)
header = next(reader)
for row in reader:
employee_id, name, department, salary = row
salary = float(salary)
print(f"Name: {name}, Salary: {salary}")
total_salary += salary
if department.strip().lower() == "engineering":
eng_salary_total += salary
eng_count += 1
print("Total salary of all employees:", total_salary)
if eng_count > 0:
print("Average Engineering salary:", eng_salary_total / eng_count)
else:
print("Average Engineering salary: No Engineering employees")
Program 10: Union and Intersection of Tuple Sets¶
set1 = {(1, 2), (3, 4), (5, 6)}
set2 = {(3, 4), (7, 8), (9, 10)}
union_result = set1.union(set2)
intersection_result = set1.intersection(set2)
print("Union:", union_result)
print("Intersection:", intersection_result)
Quick Run Notes¶
- Install NumPy if required:
pip install numpy - Keep
employee_data.csvin the same folder where you run Program 9. - Run scripts using:
python3 filename.py