0% found this document useful (0 votes)
10 views12 pages

Practical Assignment 4

The document outlines a series of practical Python programming assignments for a Computer Science course. It includes tasks such as creating user-defined modules, shuffling lists, generating random numbers, and building packages with specific functionalities. Additionally, it presents case studies for a food delivery app and a travel agency system, requiring the implementation of various modules and functions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

Practical Assignment 4

The document outlines a series of practical Python programming assignments for a Computer Science course. It includes tasks such as creating user-defined modules, shuffling lists, generating random numbers, and building packages with specific functionalities. Additionally, it presents case studies for a food delivery app and a travel agency system, requiring the implementation of various modules and functions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Department of Computer Science

Academic Year 2025-26


[Link](CS)Sem-IV

Practical Assignment No. 4

Date: 10/02/2026

1) Write a Python program to create a user defined module that will ask
your college name and will display the name of the college.
Step 1: Create a User-Defined Module
File name: [Link]
def show_college():
cname = input("Enter your college name: ")
print("College Name:", cname)
Step 2: Create the Main Program
File name: [Link]
import college
college.show_college()
2) Write a Python program to shuffle the elements of a given list. [Hint:
Use [Link]()]
import random
numbers = [1, 2, 3, 4, 5]
[Link](numbers)
print("Shuffled List:", numbers)
3) Write a python program to generate a random radius and computes
the area (use math module).
import random
import math
# Generate random radius between 1 and 10
radius = [Link](1, 10)
area = [Link] * radius * radius

print("Radius:", radius)
print("Area of Circle:", area)
4) Write a Python program to get current time and convert to local time.
(use time module)
import time
# Get current time in seconds
current_time = [Link]()
# Convert to local time
local_time = [Link](current_time)
# Display local time
print("Local Time:", [Link]("%H:%M:%S", local_time))
5) Create a package vehicle with a sub package types, and modules cars
and bikes. Each module should have a function available_models()
returning a list of models. Write a program to display them.
vehicle/
__init__.py
types/
__init__.py
[Link]
[Link]
[Link]
[Link]
def available_models():
return ["Swift", "Baleno", "Creta", "City"]
[Link]
def available_models():

return ["Pulsar", "Apache", "Royal Enfield", "FZ"]


Main Program ([Link])
from [Link] import cars, bikes
print("Available Car Models:")
print(cars.available_models())
print("\nAvailable Bike Models:")
print(bikes.available_models())
6) Build a package education with a sub package courses, containing
modules [Link] and [Link]. Each module should have a function
get_subjects(). Write a program to display all subjects.
education/
__init__.py
courses/
__init__.py
[Link]
[Link]
[Link]
[Link]
def get_subjects():
return ["Physics", "Chemistry", "Mathematics", "Biology"]
[Link]
def get_subjects():
return ["History", "Geography", "Political Science", "Economics"]
Main Program ([Link])
from [Link] import science, arts

print("Science Subjects:")
print(science.get_subjects())
print("\nArts Subjects:")
print(arts.get_subjects())
7) Write a Python program to shuffle a deck of card. Display the cards
obtained by a user in 5 attempts.
import random

# Create deck of cards


suits = ["Hearts", "Diamonds", "Clubs", "Spades"]
ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
deck = [rank + " of " + suit for suit in suits for rank in ranks]
# Shuffle the deck
[Link](deck)
print("Cards obtained by the user:")
# Display 5 cards
for i in range(5):
print(f"Attempt {i+1}: {deck[i]}")
SET B
1) Write a python program to create a module containing factorial
function, power dictionary and list of vowels. Save this as [Link].
Import variables module to print the factorial of a number, print the
power of 6, and second alphabet from the vowels list.
Step 1: Create Module
File name: [Link]
# Factorial function
def factorial(n):
fact = 1
for i in range(1, n + 1):
fact *= i
return fact
# Power dictionary
power = {
2: 4,
3: 9,
4: 16,
5: 25,
6: 36
}
# List of vowels
vowels = ['a', 'e', 'i', 'o', 'u']
Step 2: Main Program
import variables
# Factorial of a number
print("Factorial of 5:", [Link](5))
# Power of 6 from dictionary
print("Power of 6:", [Link][6])
# Second alphabet from vowels list
print("Second vowel:", [Link][1])

2) Write a python program to create a list, string and tuple in python.


Apply random module to display unique multiple random numbers or
values from above created sequence type
import random
my_list = [10, 20, 30, 40, 50]
my_string = "PYTHON"
my_tuple = (1, 2, 3, 4, 5)
print("Random from List:", [Link](my_list, 3))
print("Random from String:", [Link](my_string, 3))
print("Random from Tuple:", [Link](my_tuple, 3))
3) Create a package banking with modules [Link] and [Link].
[Link] should contain a function open_account(name), and [Link]
should contain apply_loan(amount). Write a program to demonstrate
both functions.
Package Structure
banking/
__init__.py
[Link]
[Link]
[Link]
[Link]
def open_account(name):
print("Account opened for:", name)
[Link]
def apply_loan(amount):
print("Loan applied for amount:", amount)

Main Program ([Link])


from banking import account, loan
account.open_account("Supriya")
loan.apply_loan(50000)
4) Write a Python program to get current time and apply following
functions: a) ctime() b) gmtime() c) strftime() d) strptime()
import time
# Current time
current_time = [Link]()
# a) ctime()
print("ctime():", [Link](current_time))
# b) gmtime()
gmt = [Link](current_time)
print("gmtime():", gmt)
# c) strftime()
formatted = [Link]("%d-%m-%Y %H:%M:%S", gmt)
print("strftime():", formatted)
# d) strptime()
parsed = [Link]("06-02-2026 11:30:00", "%d-%m-%Y %H:%M:
%S")
print("strptime():", parsed)
SET C
1) Create a package named library with a sub package books,
containing modules fiction and nonfiction. Each module should have a
function list_books() returning a list of book names. Write a main
program to display the lists from both.
Package Structure
library/
__init__.py
books/
__init__.py
[Link]
[Link]
[Link]
[Link]
def list_books():
return ["Harry Potter", "The Alchemist", "Lord of the Rings"]
[Link]
def list_books():
return ["Sapiens", "Atomic Habits", "Educated"]
Main Program ([Link])
from [Link] import fiction, nonfiction
print("Fiction Books:")
print(fiction.list_books())
print("\nNon-Fiction Books:")
print(nonfiction.list_books())
2) Create a package finance_tools with modules [Link] and
[Link]. Add functions to calculate interest and convert currency.
Import both in a main script and perform chained calculations.
Package Structure
finance_tools/
__init__.py
[Link]
[Link]
[Link]
[Link]
def calculate_interest(principal, rate, time):
return (principal * rate * time) / 100
[Link]
def convert_currency(amount, rate):
return amount * rate
Main Program ([Link])
from finance_tools import interest, currency

# Calculate simple interest


si = interest.calculate_interest(10000, 5, 2)
print("Simple Interest:", si)
# Convert interest amount to another currency
converted_amount = currency.convert_currency(si, 0.012)
print("Converted Amount:", converted_amount)

3) Case Study: Food Delivery App Scenario: A food delivery service needs
to handle restaurants, orders, and delivery agents. Task: Create a
Package: food_delivery  Subpackage: system o Modules: [Link],
[Link], [Link]  Each module includes functions like: o
list_restaurants() o place_order() o assign_agent()  Main script should
place an order and assign it to a delivery agent
food_delivery/
__init__.py
system/
__init__.py
[Link]
[Link]
[Link]
[Link]
Module 1: [Link]
def list_restaurants():
return ["Pizza Palace", "Burger Hub", "Spice Villa"]
Module 2: [Link]
def place_order(restaurant, item):
print(f"Order placed for {item} from {restaurant}")
return {"restaurant": restaurant, "item": item}
Module 3: [Link]
def assign_agent(order):
agent = "Agent Rahul"
print(f"Order for {order['item']} assigned to {agent}")
Main Program: [Link]
from food_delivery.system import restaurants, orders, agents
# List restaurants
rest_list = restaurants.list_restaurants()
print("Available Restaurants:", rest_list)
# Place an order
order_details = orders.place_order(rest_list[0], "Margherita Pizza")
# Assign delivery agent
agents.assign_agent(order_details)
4) Case Study: Travel Agency System Scenario: A travel agency offers
domestic and international travel packages.
Task: Create a Package travel_agency.
 Subpackage: packages with modules [Link] and [Link].
 Functions:
o get_packages()
o book_package(destination)
 Create a main script to display all packages and book one.
Package Structure
travel_agency/
__init__.py
packages/
__init__.py
[Link]
[Link]
[Link]
Module 1: [Link]
def get_packages():
return ["Goa Tour", "Kerala Backwaters", "Rajasthan Heritage"]
def book_package(destination):
print("Domestic package booked for:", destination)

Module 2: [Link]
def get_packages():
return ["Paris Trip", "Dubai Holiday", "Singapore Tour"]
def book_package(destination):
print("International package booked for:", destination)
Main Program: [Link]
from travel_agency.packages import domestic, international

# Display domestic packages


print("Domestic Packages:")
domestic_packages = domestic.get_packages()
print(domestic_packages)
# Display international packages
print("\nInternational Packages:")
international_packages = international.get_packages()
print(international_packages)

# Book one package


domestic.book_package(domestic_packages[0])

You might also like