Python practical
1. Personal Information
def personal_info():
name = "John Doe"
address = "123 Main St, Springfield, IL, 62701"
phone = "123-456-7890"
major = "Computer Science"
print("Name:", name)
print("Address:", address)
print("Phone:", phone)
print("College Major:", major)
personal_info()
2. Loan Qualifier
def loan_qualifier():
salary = float(input("Enter your annual salary: "))
years_on_job = int(input("Enter number of years at your
current job: "))
if salary >= 30000 and years_on_job >= 2:
print("You qualify for the loan.")
else:
print("You do not qualify for the loan.")
loan_qualifier()
3. Day of the Week
def day_of_week():
day_number = int(input("Enter a number (1-7): "))
Python practical 1
days = ["Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"]
if 1 <= day_number <= 7:
print("Day of the week:", days[day_number - 1])
else:
print("Error: number outside range 1-7.")
day_of_week()
4. Areas of Rectangles
def compare_rectangles():
length1 = float(input("Enter the length of the first re
ctangle: "))
width1 = float(input("Enter the width of the first rect
angle: "))
length2 = float(input("Enter the length of the second r
ectangle: "))
width2 = float(input("Enter the width of the second rec
tangle: "))
area1 = length1 * width1
area2 = length2 * width2
if area1 > area2:
print("The first rectangle has a greater area.")
elif area1 < area2:
print("The second rectangle has a greater area.")
else:
print("Both rectangles have the same area.")
compare_rectangles()
5. Age Classifier
Python practical 2
def age_classifier():
age = int(input("Enter the person's age: "))
if age <= 1:
print("This person is an infant.")
elif 1 < age < 13:
print("This person is a child.")
elif 13 <= age < 20:
print("This person is a teenager.")
else:
print("This person is an adult.")
age_classifier()
6. List Operations
def list_operations():
my_list = [1, 2, 3, 4, 5]
print("Original List:", my_list)
my_list.append(6)
print("After Append:", my_list)
my_list.insert(2, 9)
print("After Insert:", my_list)
my_list.remove(4)
print("After Remove:", my_list)
my_list.sort()
print("After Sort:", my_list)
my_list_copy = my_list.copy()
print("Copy of List:", my_list_copy)
index = my_list.index(5)
my_list[index] = 10
Python practical 3
print("After Replacing 5 with 10:", my_list)
list_operations()
7. Tuples
def tuple_operations():
my_tuple = (1, 2, 3, 4, 5)
print("Original Tuple:", my_tuple)
print("First element:", my_tuple[0])
print("Last element:", my_tuple[-1])
print("Sliced Tuple:", my_tuple[1:4])
tuple_operations()
8. Dictionaries
def dictionary_operations():
my_dict = {'name': 'John', 'age': 25, 'major': 'Compute
r Science'}
print("Original Dictionary:", my_dict)
my_dict['age'] = 26
print("After Updating Age:", my_dict)
my_dict['city'] = 'Springfield'
print("After Adding City:", my_dict)
del my_dict['major']
print("After Deleting Major:", my_dict)
for key, value in my_dict.items():
print(key, ":", value)
dictionary_operations()
Python practical 4
9. Strings
def string_operations():
my_string = "Hello, World!"
print("Original String:", my_string)
print("Uppercase:", my_string.upper())
print("Lowercase:", my_string.lower())
print("Replace World with Python:", my_string.replace
("World", "Python"))
print("Split:", my_string.split(","))
string_operations()
10. Sales Commission
def sales_commission():
sales = float(input("Enter the sales amount: "))
commission_rate = 0.1 # 10%
commission = sales * commission_rate
print("Sales Commission:", commission)
sales_commission()
Python practical 5