Python Practical
Python Practical
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: "))
loan_qualifier()
def day_of_week():
day_number = int(input("Enter a number (1-7): "))
Python practical 1
days = ["Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"]
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: "))
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)
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)
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()
def sales_commission():
sales = float(input("Enter the sales amount: "))
commission_rate = 0.1 # 10%
sales_commission()
Python practical 5