All Programs Updated
All Programs Updated
OUTPUT:
Enter your name: Priya
Choose a greeting style (e.g., Hello, Hi, Good day): Hello
Hello, Priya!
Hello,Priya how are you?
Priya say Hello
Exp 1_2
if choice == "circle":
radius = float(input("Enter the radius of the circle: "))
area = 3.14159 * radius ** 2
print(f"The area of the circle is {area:.2f}")
else:
print("Invalid choice! Please run the program again.")
OUTPUT:
Select a geometric figure: Circle, Rectangle, Triangle
Your choice: Circle
Enter the radius of the circle: 5
The area of the circle is 78.54
# Calculate allowances
da = 0.7 * basic_salary # Dearness Allowance
ta = 0.3 * basic_salary # Travel Allowance
hra = 0.1 * basic_salary # House Rent Allowance
OUTPUT:
OUTPUT:
# LIST EXAMPLE
# A list can be modified (mutable)
tasks_list = ["Clean the house", "Buy groceries", "Walk the dog"]
# TUPLE EXAMPLE
# A tuple cannot be modified (immutable), so we cannot directly
add/remove/update tasks
tasks_tuple = ("Clean the house", "Buy groceries", "Walk the dog")
OUTPUT:
After adding a task: ['Clean the house', 'Buy groceries', 'Walk the dog', 'Pay
bills']
After removing a task: ['Clean the house', 'Walk the dog', 'Pay bills']
After updating a task: ['Clean the house', 'Take the dog to the vet', 'Pay bills']
After sorting tasks: ['Clean the house', 'Pay bills', 'Take the dog to the vet']
After adding a task to tuple: ('Clean the house', 'Buy groceries', 'Walk the dog',
'Pay bills')
After removing a task from tuple: ('Clean the house', 'Walk the dog', 'Pay bills')
After updating a task in tuple: ('Clean the house', 'Take the dog to the vet', 'Pay
bills')
After sorting tasks in tuple: ('Clean the house', 'Pay bills', 'Take the dog to the
vet')
Exp_4_1
# Python program to demonstrate the use of sets and perform set operations
# Managing student enrollments in multiple exams
OUTPUT:
Students appearing for at least one exam: {'Alice', 'David', 'Hannah', 'George',
'Frank', 'Eve', 'Bob', 'Charlie'}
Students appearing in CET or JEE but not both: {'Eve', 'David', 'Bob', 'Frank'}
Updated CET enrollment after adding Ivy: {'Alice', 'David', 'Ivy', 'Bob', 'Charlie'}
records = {}
# Adding students
records[1] = {"name": "Alice", "grades": [], "attendance": 0}
records[2] = {"name": "Bob", "grades": [], "attendance": 0}
# Updating grades
records[1]["grades"].append(85)
records[1]["grades"].append(90)
records[2]["grades"].append(78)
# Updating attendance
records[1]["attendance"] += 5
records[2]["attendance"] += 3
Output:
Student: Alice, Grades: [85, 90], Attendance: 5 days, Average Grade: 87.5
Student: Bob, Grades: [78], Attendance: 3 days, Average Grade: 78.0
Exp_5
while True:
num = input("Enter a number (or type -1 to exit): ")
if num == "-1":
print("Exiting program.")
break
if num.isdigit():
num = int(num)
if num % 2 == 0:
print(f"{num} is even.")
else:
print(f"{num} is odd.")
else:
print("Invalid input. Please enter a numerical value.")
Output:
Enter a number (or type -1 to exit): 5
5 is odd.
Enter a number (or type -1 to exit): 8
8 is even.
Enter a number (or type -1 to exit): 7
7 is odd.
Enter a number (or type -1 to exit): 6
6 is even.
Enter a number (or type -1 to exit): 3
3 is odd.
Enter a number (or type -1 to exit): -1
Exiting program.
Exp_6
def fact(n):
if n==0 or n==1:
return 1
else:
return n*fact(n-1)
Output:
Enter number: 7
factorial of 7 is 5040
Exp_7_1
def is_prime(number):
if number <=1:
return False
for i in range(2,int(number**0.5)+1):
if number %i ==0:
return False
return True
Output:
def calc():
print("Welcome to the calculator: ")
print("\nSelect the operation.")
print("\n1. Addition \n2.Subtraction \n3.Multiplication \n4.Division\n")
c=input("Enter your choice: ")
calc()
Output:
1. Addition
2.Subtraction
3.Multiplication
4.Division
import re
Output:
Exp_9
try:
num1 = int(input("Enter a numerator for division: "))
num2 = int(input("Enter a denomenator for division: "))
result = num1 / num2
print("Result:", result)
except ValueError:
print("Error: Invalid input! Please enter a number.")
except ZeroDivisionError:
print("Error: Cannot divide by zero!")
except Exception as e:
print("An unexpected error occurred:", e)
finally:
print("Execution completed.")
Output:
Exp_10
import pdb
output: