Python Practical File
Name: ____________________ Class: ______ Roll No: ______
Submission Date: ____________________
Instructions: Handwrite the code in your practical file. Below are the codes and real
executed outputs (as screenshots) for reference.
Experiment 1
Experiment Name: Simple Calculator
Aim: To demonstrate Simple Calculator.
Question: Write a Python program for the above aim.
Code:
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
op = input("Enter operation (+, -, *, /): ")
if op == "+":
print("Result =", a + b)
elif op == "-":
print("Result =", a - b)
elif op == "*":
print("Result =", a * b)
elif op == "/":
if b != 0:
print("Result =", a / b)
else:
print("Cannot divide by zero")
else:
print("Invalid operation")
Sample Input/Run:
Output (screenshot):
Experiment 2
Experiment Name: Paragraph Analyzer
Aim: To demonstrate Paragraph Analyzer.
Question: Write a Python program for the above aim.
Code:
text = input("Enter a paragraph: ")
vowels = 0
consonants = 0
special = 0
words = len([Link]())
for ch in text:
if [Link]() in "aeiou":
vowels += 1
elif [Link]():
consonants += 1
elif [Link]() or ch == " ":
continue
else:
special += 1
print("Vowels:", vowels)
print("Consonants:", consonants)
print("Words:", words)
print("Special characters:", special)
Sample Input/Run:
Output (screenshot):
Experiment 3
Experiment Name: Total, Average and Grade
Aim: To demonstrate Total, Average and Grade.
Question: Write a Python program for the above aim.
Code:
n = int(input("How many subjects? "))
marks = []
for i in range(n):
m = float(input("Enter marks: "))
[Link](m)
total = sum(marks)
avg = total / n
print("Total =", total)
print("Average =", avg)
if avg >= 90:
print("Grade A+")
elif avg >= 80:
print("Grade A")
elif avg >= 70:
print("Grade B")
elif avg >= 60:
print("Grade C")
else:
print("Grade D")
Sample Input/Run:
Output (screenshot):
Experiment 4
Experiment Name: Basic Banking Operations
Aim: To demonstrate Basic Banking Operations.
Question: Write a Python program for the above aim.
Code:
balance = 1000
while True:
print("\n1. Deposit 2. Withdraw 3. Balance 4. Exit")
ch = int(input("Enter choice: "))
if ch == 1:
amt = float(input("Enter amount: "))
balance += amt
print("Deposited.")
elif ch == 2:
amt = float(input("Enter amount: "))
if amt <= balance:
balance -= amt
print("Withdrawn.")
else:
print("Not enough balance.")
elif ch == 3:
print("Balance =", balance)
elif ch == 4:
break
else:
print("Invalid choice")
Sample Input/Run:
Output (screenshot):
Experiment 5
Experiment Name: Employee Details using Dictionary
Aim: To demonstrate Employee Details using Dictionary.
Question: Write a Python program for the above aim.
Code:
emp = {}
while True:
print("\[Link] [Link] [Link] [Link]")
ch = int(input("Enter choice: "))
if ch == 1:
eid = input("Enter ID: ")
name = input("Enter Name: ")
sal = float(input("Enter Salary: "))
emp[eid] = [name, sal]
elif ch == 2:
for i in emp:
print(i, emp[i][0], emp[i][1])
elif ch == 3:
eid = input("Enter ID to search: ")
if eid in emp:
print(eid, emp[eid][0], emp[eid][1])
else:
print("Not found")
else:
break
Sample Input/Run:
Output (screenshot):
Experiment 6
Experiment Name: Word Frequency
Aim: To demonstrate Word Frequency.
Question: Write a Python program for the above aim.
Code:
line = input("Enter a line: ")
words = [Link]().split()
freq = {}
for w in words:
if w in freq:
freq[w] += 1
else:
freq[w] = 1
for x in freq:
print(x, ":", freq[x])
Sample Input/Run:
Output (screenshot):
Experiment 7
Experiment Name: NumPy Sales Analysis
Aim: To demonstrate NumPy Sales Analysis.
Question: Write a Python program for the above aim.
Code:
import numpy as np
sales = [Link]([1200,1500,1800,1600,2000,2200])
print("Total =", [Link]())
print("Average =", [Link]())
print("Maximum =", [Link]())
Sample Input/Run:
Output (screenshot):
Experiment 8
Experiment Name: Pandas DataFrame of Marks
Aim: To demonstrate Pandas DataFrame of Marks.
Question: Write a Python program for the above aim.
Code:
import pandas as pd
data = {
"Name":["A","B","C","D"],
"Math":[78,90,67,88]
}
df = [Link](data)
print(df)
print("\nStudents with Math > 80")
print(df[df["Math"] > 80])
print("\nSorted by Marks")
print(df.sort_values("Math"))
Sample Input/Run:
Output (screenshot):
Experiment 9
Experiment Name: Matplotlib: Bar & Scatter
Aim: To demonstrate Matplotlib: Bar & Scatter.
Question: Write a Python program for the above aim.
Code:
import [Link] as plt
months = ["Jan","Feb","Mar","Apr"]
sales = [1000,1500,1300,1700]
[Link](months, sales)
[Link]("Sales Bar Chart")
[Link]("[Link]")
[Link]()
[Link]([1,2,3,4], sales)
[Link]("Scatter Plot")
[Link]("[Link]")
[Link]()
Sample Input/Run:
Output (screenshot):
Experiment 10
Experiment Name: Regex: Find Emails & Phone Numbers
Aim: To demonstrate Regex: Find Emails & Phone Numbers.
Question: Write a Python program for the above aim.
Code:
import re
text = input("Enter text: ")
emails = [Link](r"\S+@\S+\.\S+", text)
phones = [Link](r"\d{10}", text)
print("Emails:", emails)
print("Phone numbers:", phones)
Sample Input/Run:
Output (screenshot):
Experiment 11
Experiment Name: Linear Regression (Demo)
Aim: To demonstrate Linear Regression (Demo).
Question: Write a Python program for the above aim.
Code:
from sklearn.linear_model import LinearRegression
import numpy as np
X = [Link]([[1],[2],[3],[4],[5]])
y = [Link]([2,4,6,8,10])
model = LinearRegression()
[Link](X, y)
print("Coefficient =", model.coef_)
print("Intercept =", model.intercept_)
print("Prediction for 6 =", [Link]([[6]]))
Sample Input/Run:
Output (screenshot):
Experiment 12
Experiment Name: Random Forest (Demo)
Aim: To demonstrate Random Forest (Demo).
Question: Write a Python program for the above aim.
Code:
from [Link] import RandomForestClassifier
from sklearn.model_selection import train_test_split
X = [[20,30],[25,40],[35,60],[45,80],[50,90]]
y = [0,0,1,1,1]
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3)
model = RandomForestClassifier()
[Link](X_train, y_train)
print("Predictions:", [Link](X_test))
Sample Input/Run:
Output (screenshot):
Extra Notes Page 1
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Extra Notes Page 2
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Extra Notes Page 3
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Extra Notes Page 4
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Extra Notes Page 5
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Extra Notes Page 6
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.
Notes: Write your observations here. Write your observations here. Write your
observations here. Write your observations here. Write your observations here. Write
your observations here. Write your observations here. Write your observations here.