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

Python All Exp

The document contains multiple Python programs that demonstrate various functionalities including calculating areas of geometric figures, managing task lists using lists and tuples, performing arithmetic operations, handling exceptions, validating phone numbers and email IDs, and conducting statistical analysis using NumPy. Each program prompts the user for input and performs specific tasks such as calculating gross salary, checking if a number is prime, and performing element-wise operations on arrays. The document serves as a comprehensive guide for beginners to understand and implement basic Python programming concepts.

Uploaded by

gamerxsatish
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)
18 views12 pages

Python All Exp

The document contains multiple Python programs that demonstrate various functionalities including calculating areas of geometric figures, managing task lists using lists and tuples, performing arithmetic operations, handling exceptions, validating phone numbers and email IDs, and conducting statistical analysis using NumPy. Each program prompts the user for input and performs specific tasks such as calculating gross salary, checking if a number is prime, and performing element-wise operations on arrays. The document serves as a comprehensive guide for beginners to understand and implement basic Python programming concepts.

Uploaded by

gamerxsatish
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

Write a python program to calculate areas of any geometric

figures like circle, rectangle and triangle


int(input(" Enter the radius of circle:"))

l1=int(input(" Enter the length of the rectangle:"))

b1=int(input(" Enter the base of rectangle:"))

h1=int(input(" Enter the height of rectangle:"))

b2=int(input(" Enter the base of rectangle:"))

area1=3.14*radius*radius

area2=l1*b1

area3=0.5*h1*b2

print(f" the area is circle is {area1},the area of rectangle is


{area2},the area of triangle is {area3}")

Write a Python program to calculate the gross salary of an


employee. The program should prompt the user for the basic
salary (BS) and then compute the dearness allowance (DA) as
70% of BS, the travel allowance (TA) as 30% of BS, and the
house rent allowance (HRA) as 10% of BS. Finally, it should
calculate the gross salary as the sum of BS, DA, TA, and HRA
and display the result.

bs=float(input("Enter the value:"))

da=float(0.7*bs)

print(da)

ta=float(0.3*bs)

print(ta)

hra=float(0.1*bs)

print(hra)

gs=float(bs+da+ta+hra)

print(gs)
Write a Python program to explore basic arithmetic operations.
The program should prompt the user to enter two numbers and
then perform addition, subtraction, multiplication, division, and
modulus operations on those numbers. The results of each
operation should be displayed to the user.
a=input("Enter the value a :")

b=input("Enter the value b :")

add=int(a)+int(b)

print(add)

sub=int(a)-int(b)

print(sub)

mul=int(a)*int(b)

print(mul)

div=int(a)/int(b)

print(div)

mod=int(a)%int(b)

print(mod)

Develop a Python program to manage a task list using lists ,


including adding, removing, updating, and sorting tasks.
# LIST

task_list=["Clean the house","Buy groceries","Walk the dog "]

task_list.append("Pay bilis")

print("After adding a task:",task_list)

task_list.remove("Buy groceries")

print("After removing a task:",task_list)

task_list[1]= "Take the dog to the vet"

print("After updating a task:",task_list)

task_list.sort()
print("After sorting tasks:",task_list)

Develop a Python program to manage a task list using tuples,


including adding, removing, updating, and sorting tasks.
# TUPLE

tasks_tuple = ("Clean the house", "Buy groceries", "Walk the


dog")

print("Initial tuple:", tasks_tuple)

tasks_tuple = tasks_tuple + ("Pay bills",)

print("\nAfter adding a task to tuple:", tasks_tuple)

temp_list = list(tasks_tuple)

temp_list.remove("Buy groceries")

tasks_tuple = tuple(temp_list)

print("After removing a task from tuple:", tasks_tuple)

temp_list = list(tasks_tuple)

temp_list[1] = "Take the dog to the vet"

tasks_tuple = tuple(temp_list)

print("After updating a task in tuple:", tasks_tuple)

temp_list = list(tasks_tuple)

temp_list.sort()

tasks_tuple = tuple(temp_list)

print("After sorting tasks in tuple:", tasks_tuple)


Create a Python code to demonstrate the use of sets and
perform set operations (union, intersection, difference) to
manage student enrollments in multiple courses / appearing
for multiple entrance exams like CET, JEE, NEET etc.

# Sample student enrollments

cet_students = {"Alice", "Bob", "Charlie", "David"}

jee_students = {"Charlie", "Eve", "Frank", "Alice"}

neet_students = {"George", "Hannah", "Alice", "Eve"}

print("Students enrolled in CET:", cet_students)

print("Students enrolled in JEE:", jee_students)

print("Students enrolled in NEET:", neet_students)

all_students = cet_students.union(jee_students, neet_students)

print("\nStudents appearing for at least one exam:", all_students)

common_students = cet_students.intersection(jee_students, neet_students)

print("\nStudents appearing for all three exams:", common_students)

cet_not_jee = cet_students.difference(jee_students)

print("\nStudents appearing for CET but not JEE:", cet_not_jee)

cet_or_jee_not_both = cet_students.symmetric_difference(jee_students)

print("\nStudents appearing in CET or JEE but not both:", cet_or_jee_not_both)

student_name = "Alice"

is_enrolled = student_name in all_students

print(f"Is {student_name} enrolled in any exam?", is_enrolled)

cet_students.add("Ivy")

print("\nUpdated CET enrollment after adding Ivy:", cet_students)

jee_students.discard("Frank")

print("Updated JEE enrollment after removing Frank:", jee_students)


Develop a Python program that takes a numerical input and
identifies whether it is even or odd, utilizing conditional
statements and loops.
num=int(input("Enter a number:"))

if num%2==0:

print(f"{num} is an even number")

else:

print(f"{num} is an odd number")

.
Develop a Python program that takes a numerical input and
identifies whether it is even or odd, utilizing loops(do..while,for)

Using WHILE loop

# Get input number

num = int(input("Enter a number: "))

# Method 1: Using WHILE loop (simulates do-while)

count = 0

while count < 2: # Runs exactly 2 times

if num % 2 == 0:

print(f"{num} is EVEN")

else:

print(f"{num} is ODD")

count += 1

break # Exit after first iteration (do-while style)

Using FOR loop

# Get input number

num = int(input("Enter a number: "))

#Method 2: Using FOR loop

for i in range(1):

remainder = num % 2

result = "EVEN" if remainder == 0 else "ODD"

print(f"{num} is {result}")
Design a Python program to compute the factorial of a given
integer N.
num=int(input("Enter a number:"))

fact=1

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

fact=fact*i

print("Factorial of value is",fact)

write a Python program to analyze the input number is prime or


not.
number = int(input("ENTER A NUMBER:"))

if number <= 1:

print("COMPOSITE NUMBER")

else:

is_prime = True

for i in range(2, number):

if number % i == 0:

is_prime = False

break

if is_prime:

print("PRIME NUMBER")

else:

print("COMPOSITE NUMBER")
Implement a simple Python calculator that takes user input and
performs basic arithmetic operations (addition, subtraction,
multiplication, division) using functions.

def add(a, b):

addition = a + b

print("Addition is:", addition)

def sub(a, b):

subtraction = a - b

print("Subtraction is:", subtraction)

def mult(a, b):

multiplication = a * b

print("Multiplication is:", multiplication)

def quo(a, b):

if b == 0:

print("Error: Division by zero is not allowed.")

return

quotient = a / b

print("Quotient is:", quotient)

print("Select an operation")

print("1 - Addition")

print("2 - Subtraction")

print("3 - Multiplication")

print("4 - Division")

try:

choice = int(input("Enter number of choice to perform


operation: "))

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))


match choice:

case 1:

add(a, b)

case 2:

sub(a, b)

case 3:

mult(a, b)

case 4:

quo(a, b)

case _:

print("Enter valid choice")

except ValueError:

print("Invalid input. Please enter numbers for choice and


operands.")

Write a Python program that takes two numbers as input and


performs division. Implement exception handling to manage
division by zero and invalid input errors gracefully.
try:

a = int(input("Enter first number"))

b = int(input("Enter second number"))

result = a / b

print("Division is:", result)

except ZeroDivisionError:

print("Cannot divide by zero")

except ValueError:

print("Enter valid number value")


finally:

print("This will execute irrespective of error or no error")

try:

a=int(input("Enter first number"))

b=int(input("Enter second number"))

result=a/b

print("Division is:", result)

except Exception as e:

print("Your error is",e)

finally:

print("This will accept inspite of error or no error")

Write a Python script that prompts the user to enter their


phone number. It then employs Regular Expressions to verify if
these inputs adhere to standard phone number formats.

# Phone Number Validation

import re

phone = input("Enter phone number:")

phone_pattern = r'^\d{10}$'

if [Link](phone_pattern, phone):

print("Valid phone number")

else:

print("Invalid phone number")


Write a Python script that prompts the user to enter their
email ID. It then employs Regular Expressions to verify if these
inputs adhere to standard email address formats

# Email ID Validation

import re

email = input("Enter email ID:")

email_pattern = r'^[\w\.-]+@[\w\-]+\.\w+'

if [Link](email_pattern, email):

print("Valid email ID")

else:

print("Invalid email ID")

Develop a Python script to create two arrays of the same shape


and perform element-wise addition, subtraction, multiplication,
and division

import numpy as np

array1 = [Link]([1, 2, 3])

array2 = [Link]([4, 5, 6])

print("Array 1:", array1)

print("Array 2:", array2)

addition = [Link](array1, array2)

print("Element wise addition:", addition)

subtraction = [Link](array1, array2)

print("Element wise subtraction:", subtraction)

multiplication = [Link](array1, array2)

print("Element wise multiplication:", multiplication)

division = [Link](array1, array2)


print("Element wise division:", division)

dot_product = [Link](array1, array2)

print("Dot Product: ", dot_product)

cross_product = [Link](array1, array2)

print("Cross Product:", cross_product)

Write a Python program to calculate mean, median, standard


deviation, variance, and correlation coefficients of a given array

import numpy as np

array = [Link]([10,20,30,40,50,60,70,80,90,100])

#Mean

mean = [Link](array)

print(f"Mean: {mean}")

#Median

median = [Link](array)

print(f"Median: {median}")

#Standard Deviation

std_dev = [Link](array)

print(f"Standard Deviation: {std_dev}")

#Variance

variance = [Link](array)

print(f"Variance: {variance}")

You might also like