0% found this document useful (0 votes)
5 views

Python Programming PRACTICAL NO.17 ANSWERS

The document outlines a practical Python programming exercise focusing on the Math, Random, and OS modules. It includes example programs for displaying a calendar, calculating the area of a circle, and generating random numbers. The conclusion emphasizes the utility of these modules in simplifying programming tasks.
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)
5 views

Python Programming PRACTICAL NO.17 ANSWERS

The document outlines a practical Python programming exercise focusing on the Math, Random, and OS modules. It includes example programs for displaying a calendar, calculating the area of a circle, and generating random numbers. The conclusion emphasizes the utility of these modules in simplifying programming tasks.
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
You are on page 1/ 5

🌟 Diplomatech Academy 🌟

Manual Solutions and outputs


Python Programming Course Code: 314004
-Mohade Sir©
Practical No. 17: Write a python program to demonstrate the use of
following
module: 1. Math module 2. Random module 3. OS module

ir
eS
ad
oh
M

IX Conclusion:
Ans

We have successfully explored the Math, Random, and OS modules in Python.


These modules provide essential functionalities that simplify various programming
tasks:

1.​ The Math module enables advanced mathematical computations


effortlessly.
2.​ The Random module helps generate random numbers, making it useful in
simulations and cryptography.

X Practical related questions


1.Write a Python program to display calendar of given month using Calendar
module.

ir
Ans.

Here's a simple Python program to display the calendar of a given month using the

eS
calendar module:

import calendar

# Take year and month input from the user


year = int(input("Enter year: "))
ad
month = int(input("Enter month (1-12): "))

# Display the calendar for the given month and year


print(calendar.month(year, month))
oh

Example Output:
Enter year: 2024
M

Enter month (1-12): 3


March 2024
Mo Tu We Th Fr Sa Su
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
🚀
This program takes year and month as input and prints the corresponding
calendar.

2.Write a python program to calculate area of circle using inbuilt Math


module.

Ans.

Here's a Python program to calculate the area of a circle using the math module:

ir
import math

eS
# Take radius input from the user

radius = float(input("Enter the radius of the circle: "))


ad
# Calculate the area using the formula πr²

area = math.pi * radius ** 2


oh

# Display the result

print(f"The area of the circle is: {area:.2f}")


M

Example Output:

Enter the radius of the circle: 5

The area of the circle is: 78.54


3.What is the output of the following program?

import random

print random.randint(0, 5)

print random.random()

print random.random() * 100

ir
List = [1, 4, True, 800, "Python", 27, "hello"]

eS
print random.choice(List)

Ans.

0.72648124098
ad
52.4871928345

Python
oh

4.What is the output of the following program?

import datetime
M

from datetime import date

import time

print time.time()

print date.fromtimestamp(454554)

Ans.
1709238473.6521988 # (Example output - This value will change as it's the
current epoch time)

1970-01-06 # (Date corresponding to the given timestamp 454554)

ir
eS
ad
oh
M

You might also like