PYTHON
PYTHON
branch.
CODE:-
CODE:-
def circle_perimeter(radius)
basic salary (BS) ,dearness allowance (DA) 80% of BS, the travel allowance (TA) 20% of BS,
CODE:-
user to enter two numbers and then perform addition, subtraction, multiplication, division, and
CODE:-
CODE:-
list= [T1,T2]
print('The Tasks Are:',list)
print('Adding a new task')
T3=input('Enter Task 3:')
list.append(T3)
print('Updated Task List:',list)
print('---------------------------------')
print('Deleting a task')
rem=input('Enter Task to be deleted:')
list.remove(rem)
print('Updated Task List:',list)
6) Develop a Python program to manage a task list using lists including updating and sorting tasks.
CODE:-
list= [T1,T2]
print('The Tasks Are:',list)
print('Sorting Task List')
list.sort()
print('Sorted Task List:',list)
print('---------------------------------')
print('Changing/Updating a task')
no=int(input('Enter the Task number to be updated:'))
newtask=input('Enter the updated value of Task:')
list[no-1]=newtask
print('Updated Task List:',list)
print('---------------------------------')
7) Create a Python code to demonstrate the use of sets and perform set operations (union,
difference)
to manage student enrollments in multiple courses / appearing for multiple entrance exams like
CODE:-
difference) to manage student enrollments in multiple courses / appearing for multiple entrance
CODE:-
CODE:-
CODE:-
def check_divisibility_by_3(number):
if number % 3 == 0:
else:
result = check_divisibility_by_3(input_number)
print(result)
except ValueError:
CODE:-
CODE:-
def is_prime(n):
if n < 2:
return False
i = 2
while i*i <= n:
if n % i == 0:
return False
i += 1
return True
operations
CODE:-
def calculator():
print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
if choice == '1':
print("{0} + {1} = {2}".format(num1,num2,add(num1,num2)))
elif choice == '2':
print("{0} - {1} =
{2}".format(num1,num2,subtract(num1,num2)))
elif choice == '3':
print("{0} * {1} =
{2}".format(num1,num2,multiply(num1,num2)))
elif choice == '4':
print("{0} / {1} =
{2}".format(num1,num2,divide(num1,num2)))
else:
print("Invalid input. Please choose a valid operation.")
calculator()
ch=input("Do you want to perform another operation (y/n)")
while (ch=='y') or (ch=='Y') or (ch=='n') or (ch=='N') :
if ((ch=='y') or (ch=='Y')):
calculator()
else:
exit()
ch=input("Do you want to perform another operation (y/n)")
else:
print("Invalid Response!Exiting...!")
14) Write a Python program that takes two numbers as input and performs division and manage
division by zero error.
CODE:-
def divide_numbers():
try:
if num2 == 0:
print("Result:", result)
except ValueError:
except ZeroDivisionError as e:
print("Error:", e)
except Exception as e:
divide_numbers()
15) Demonstrate classes and objects using a program(using __init__).
CODE:-
16) Write a Python program to create a 1D NumPy array. Perform basic operations like reshaping and
indexing.
CODE:-
import numpy as np #importing numpy
arr_1d = np.array([1, 2, 3, 4, 5])
print("Original 1D Array:", arr_1d)
arr_1d_reshaped = arr_1d.reshape(1, 5)
print("Reshaped 1D Array to 2D:", arr_1d_reshaped)
17) Write a Python program to create a 2D NumPy array. Perform basic operations like reshaping and
indexing.
CODE:-
arr_2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print("Original 2D Array:")
print(arr_2d)
indexing.
CODE:-
arr_3d = np.array([[[1, 2], [3, 4]], [[5, 6], [7,
8]]]) print("Original 3D Array:") print(arr_3d)
arr_3d_reshaped = arr_3d.reshape(2, 4)
print("Reshaped 3D Array to 2D:")
print(arr_3d_reshaped)
19) Develop a Python script to create two arrays of the same shape and perform element-wise
addition.
CODE:-
Array1 = np.array([1,2,3]
[6,5,4])
Array2 = np.array([4,5,6]
[3,2,1])
Print(“Array1:”)
Print(“n\Array2:”)
print("\nElement-wise Addition (Array1 + Array2):")
20) Write a Python program to calculate mean, median and standard deviation for a 1D array.
CODE:-
# Given array (1D array)
array1 = np.array([10, 20, 30, 40, 50])
#
Mean
mean = np.mean(array1)
print(f"Mean: {mean}")
# Median
median = np.median(array1)
print(f"Median: {median}")