0% found this document useful (0 votes)
3 views13 pages

Adv Py Assignment 4

The document outlines a series of programming assignments involving the creation of modules and packages in Python. It includes tasks such as creating a user-defined module to display a college name, shuffling a list, calculating the area of a circle using a random radius, and managing a package structure for vehicles. Additionally, it provides examples of using built-in libraries like random and time, along with instructions for running the code on Ubuntu.

Uploaded by

Pratik Adhav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views13 pages

Adv Py Assignment 4

The document outlines a series of programming assignments involving the creation of modules and packages in Python. It includes tasks such as creating a user-defined module to display a college name, shuffling a list, calculating the area of a circle using a random radius, and managing a package structure for vehicles. Additionally, it provides examples of using built-in libraries like random and time, along with instructions for running the code on Ubuntu.

Uploaded by

Pratik Adhav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# Assignment 4 — SET A

Modules & Packages set includes module creation, random, math, time, and packages.

SET A — Q1

## Create a user-defined module that asks college name and displays it

### Step 1 — Create module file

### [Link]

```python

# function to ask and display college name

def show_college():

name = input("Enter your college name: ")

print("College Name is:", name)

```

### [Link]

```python

import college # importing our module

college.show_college() # calling function from module


```

---

`def show_college()` → defines function inside module

`input()` → takes user input

`print()` → displays result

`import college` → loads module file

`college.show_college()` → calls function using module name

---

### Ubuntu Run Steps

```

gedit [Link]

gedit [Link]

python3 [Link]

```

---

# SET A — Q2

## Shuffle elements of list


```python

import random

data = [10, 20, 30, 40, 50]

[Link](data)

print("Shuffled list:", data)

```

### Explanation

`import random` → built-in random module

`shuffle()` → rearranges list in-place

No return value — list itself changes

Run:

```bash

python3 [Link]

```

---

# SET A — Q3
## Random radius → area using math

```python

import random

import math

radius = [Link](1, 10)

area = [Link] * radius * radius

print("Radius:", radius)

print("Area:", area)

```

### Explanation

`randint(1,10)` → random radius

`[Link]` → constant π

Area formula = π r²

---

# SET A — Q4

## Current time → local time


```python

import time

current = [Link]()

local = [Link](current)

print("Seconds:", current)

print("Local time:", local)

```

---

# SET A — Q5 (Question)

**Create a package named `vehicle` with a subpackage `types` containing modules


`[Link]` and `[Link]`. Import both modules and display available models.**

Folder Structure:

project_folder/

├── [Link]

└── vehicle/

├── __init__.py

└── types/

├── __init__.py

├── [Link]
└── [Link]

---

# Step 1 — Create folders manually (Ubuntu Terminal)

Now your structure is:

```

vehicle/

types/

```

# Step 2 — Create package marker files (important)

Create `__init__.py` files so Python treats folders as packages.

```bash

gedit vehicle/__init__.py

```

Save and close (can remain empty).

```bash

gedit vehicle/types/__init__.py

```
Save and close.

---

# Step 3 — Create module files with gedit

## [Link]

```bash

gedit vehicle/types/[Link]

```

```python

def available_models():

return ["Swift", "City", "XUV"]

```

Save → Close.

---

## [Link]

```bash

gedit vehicle/types/[Link]
```

Paste:

```python

def available_models():

return ["Activa", "Pulsar", "Duke"]

```

Save → Close.

---

# Step 4 — Create main program

```bash

gedit [Link]

```

Paste:

```python

from [Link] import cars, bikes

print("Cars:", cars.available_models())

print("Bikes:", bikes.available_models())
```

Save → Close.

---

# Step 5 — Run program

Make sure you are in the folder where `[Link]` exists:

```bash

python3 [Link]

```

Expected output:

```

Cars: ['Swift', 'City', 'XUV']

Bikes: ['Activa', 'Pulsar', 'Duke']

```

Question 6 is similar like Question 5

# SET A — Q7

## Shuffle deck — 5 attempts


```python

import random

cards = ["A", "K", "Q", "J", "10"]

for i in range(5):

[Link](cards)

print("Attempt", i+1, ":", cards)

```

---

# SET B — (Module + Package variations)

---

# SET B — Q1 [Link] module

### [Link]

```python

def factorial(n):

f=1

for i in range(1, n+1):

f=f*i

return f
powers = {6: 36}

vowels = ['a','e','i','o','u']

```

### [Link]

```python

import variables

print([Link](5))

print([Link][6])

print([Link][1])

```

---

# SET B — Q2 random from list/string/tuple

```python

import random

lst = [1,2,3,4,5]

st = "python"

tp = (10,20,30,40)
print([Link](lst,3))

print([Link](st,3))

print([Link](tp,2))

```

---

# SET B — Q3 banking package

```

banking/[Link]

banking/[Link]

```

### [Link]

```python

def open_account(name):

print("Account opened for", name)

```

### [Link]

```python

def apply_loan(amount):
print("Loan applied:", amount)

```

### [Link]

```python

from banking import account, loan

account.open_account("Pratik")

loan.apply_loan(50000)

```

---

# SET B — Q4 time functions

```python

import time

print([Link]())

print([Link]())

print([Link]("%d-%m-%Y"))

print([Link]("05-02-2026","%d-%m-%Y"))

```

You might also like