python final ankit
python final ankit
-1323472 BCA-406
A
(BCA-406)
Practical File On
Python Programing Lab
BCA-406
1
Roll no.-1323472 BCA-406
SN NO. PROGRAM LIST PAGE NO. DATE SIGNATURE
01. Installation of python and Jupyter Notebook (IDE
for Python) and test a basic python program in
both Script and Interactive mode
2
Roll no.-1323472 BCA-406
Practical-01
Installation of python and Jupyter Notebook (IDE for Python) and test a basic python
program in both Script and Interactive mode
➢ Download Python:
• Go to the official Python website: https://www.python.org/downloads/
• Choose the appropriate version for your operating system (Windows, macOS, Linux).
• Download and install Python. During installation, make sure to check the box to "Add Python
to PATH" before clicking "Install Now."
➢ Verify Python installation: Open a terminal or command prompt and run the following
command to verify that Python is installed correctly:
➢ Install Jupyter using pip: After installing Python, open a terminal or command prompt and run the
following command to install Jupyter Notebook using pip:
➢ Launch Jupyter Notebook: After installation, you can launch Jupyter Notebook by running the
following command in your terminal or command prompt:
3
Roll no.-1323472 BCA-406
➢ Interactive Mode in Python: - tab window button and search idle to enter the Python interactive
shell.
➢ Script Mode in Python: - Open any text editor (like Notepad, VSCode, etc.) and create a new file
called hello_world.py.
• Save the file and run it in the terminal or command prompt by navigating to the directory
where the file is saved and executing:
Output: -
4
Roll no.-1323472 BCA-406
Practical-02
To write a python program that takes in command line arguments as input and
print the number of arguments.
Source code: -
Import sys
Output: -
5
Roll no.-1323472 BCA-406
Practical-03
Write a python program to illustrate the various functions of math module.
Source Code: -
import math
# 1. Math Constants
print("Math Constants:")
print(f"pi: {math.pi}") # Value of pi
print(f"e: {math.e}") # Value of e (Euler's number)
print(f"tau: {math.tau}") # Value of tau (2 * pi)
print(f"inf: {math.inf}") # Positive infinity
print(f"nan: {math.nan}") # Not a number (NaN)
print()
# 3. Trigonometric Functions
print("Trigonometric Functions:")
angle_rad = math.radians(45) # Convert 45 degrees to radians
print(f"sin(45 degrees in radians): {math.sin(angle_rad)}") # Sine of angle
print(f"cos(45 degrees in radians): {math.cos(angle_rad)}") # Cosine of angle
print(f"tan(45 degrees in radians): {math.tan(angle_rad)}") # Tangent of angle
print(f"degrees({math.pi / 4} radians): {math.degrees(math.pi / 4)}") # Convert radians to degrees
print()
# 4. Logarithmic Functions
print("Logarithmic Functions:")
print(f"log(10): {math.log(10)}") # Natural logarithm (base e)
print(f"log10(100): {math.log10(100)}") # Logarithm with base 10
print(f"log2(16): {math.log2(16)}") # Logarithm with base 2
print()
# 6. Hyperbolic Functions
print("Hyperbolic Functions:")
print(f"sinh(1): {math.sinh(1)}") # Hyperbolic sine
print(f"cosh(1): {math.cosh(1)}") # Hyperbolic cosine
print(f"tanh(1): {math.tanh(1)}") # Hyperbolic tangent
print()
6
Roll no.-1323472 BCA-406
# 7. Rounding Functions
print("Rounding Functions:")
print(f"floor(4.7): {math.floor(4.7)}") # Greatest integer less than or equal to x
print(f"ceil(4.7): {math.ceil(4.7)}") # Smallest integer greater than or equal to x
print(f"trunc(4.7): {math.trunc(4.7)}") # Truncate the decimal part
print(f"round(4.7): {round(4.7)}") # Round to the nearest integer
print()
# 9. Special Functions
print("Special Functions:")
print(f"gamma(5): {math.gamma(5)}") # Gamma function (n-1)!
print(f"lgamma(5): {math.lgamma(5)}") # Logarithm of the absolute value of the Gamma function
7
Roll no.-1323472 BCA-406
Output: -
8
Roll no.-1323472 BCA-406
Practical-04
Write a menu driven program in python to calculate the area of different shapes using
a while loop.
Source code: -
import math
def calculate_area_of_circle(radius):
return math.pi * radius ** 2
def calculate_area_of_square(side):
return side ** 2
def menu():
while True:
print("\nMenu:")
print("1. Calculate Area of Circle")
print("2. Calculate Area of Rectangle")
print("3. Calculate Area of Triangle")
print("4. Calculate Area of Square")
print("5. Exit")
choice = input("Enter your choice (1/2/3/4/5): ")
if choice == '1':
radius = float(input("Enter the radius of the circle: "))
area = calculate_area_of_circle(radius)
print(f"The area of the circle is: {area:.2f}")
elif choice == '2':
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
area = calculate_area_of_rectangle(length, width)
print(f"The area of the rectangle is: {area:.2f}")
9
Roll no.-1323472 BCA-406
Output: -
10
Roll no.-1323472 BCA-406
Practical-05
Write a program in python to create a list and apply all the operation applicable for
the list.
Source code: -
# Create a list
my_list = [10, 20, 30, 40, 50]
print("Initial List:", my_list)
11
Roll no.-1323472 BCA-406
Output: -
12
Roll no.-1323472 BCA-406
Practical-06
Write a program in python to create a tuple and apply all the operation applicable for
the list. Also show that tuples are immutable.
Source Code: -
# Creating a tuple
my_tuple = (1, 2, 3, 4, 5)
13
Roll no.-1323472 BCA-406
# Attempting list operations on tuple (which will fail)
print("\n\nTrying to Modify Tuple (This will cause an error)")
try:
my_tuple[0] = 10 # Tuples do not support item assignment
except TypeError as e:
print("Error:", e)
try:
my_tuple.append(6) # Tuples do not support append
except AttributeError as e:
print("Error:", e)
try:
my_tuple.remove(3) # Tuples do not support remove
except AttributeError as e:
print("Error:", e)
14
Roll no.-1323472 BCA-406
Output: -
15
Roll no.-1323472 BCA-406
Practical-07
Write a program in python to create a Dictionary and apply all the operation
applicable for the list.
Source code: -
# Create a dictionary with list values
my_dict = {
"numbers": [1, 2, 3, 4, 5],
"fruits": ["apple", "banana", "cherry"],
"letters": ["a", "b", "c", "d"]
}
16
Roll no.-1323472 BCA-406
Output: -
17