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

FE_Python_Practical

The document contains Python code examples for various programming tasks, including greeting users, calculating areas of shapes, computing gross salaries, and performing arithmetic operations. It also demonstrates managing a task list with lists and tuples, performing set operations for student enrollments in exams, and manipulating a dictionary of student records. Each section includes code snippets and outputs to illustrate the functionality.

Uploaded by

jaymala.chavan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

FE_Python_Practical

The document contains Python code examples for various programming tasks, including greeting users, calculating areas of shapes, computing gross salaries, and performing arithmetic operations. It also demonstrates managing a task list with lists and tuples, performing set operations for student enrollments in exams, and manipulating a dictionary of student records. Each section includes code snippets and outputs to illustrate the functionality.

Uploaded by

jaymala.chavan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment 1

1.A)

print ("Hello, Welcome to Python!")

n = input("Enter your name : ")


print(f"Hello, {n}! Welcome to the Python Programming!")

2.B)

import math

# Predefined values
radius = 5
length = 10
width = 4
side = 6

# Function to calculate area of circle


def area_of_circle(radius):
return math.pi * radius ** 2

# Function to calculate area of rectangle


def area_of_rectangle(length, width):
return length * width

# Function to calculate area of square


def area_of_square(side):
return side ** 2

# Calculate and print areas


circle_area = area_of_circle(radius)
rectangle_area = area_of_rectangle(length, width)
square_area = area_of_square(side)

print(f"Area of circle with radius {radius} : {circle_area:.2f}")


print(f"Area of rectangle with length {length} and width {width} :
{rectangle_area:.2f}")
print(f"Area of square with side {side} : {square_area:.2f}")
1.C)

# Input the basic salary from the user


basic_salary = float(input("Enter the basic salary of the employee : "))

# Calculate allowances
DA = 0.70 * basic_salary # 70% of basic salary
TA = 0.30 * basic_salary # 30% of basic salary
HRA = 0.10 * basic_salary # 10% of basic salary

# Calculate the gross salary


gross_salary = basic_salary + DA + TA + HRA

# Display the gross salary


print("The gross salary of the employee is : ",gross_salary)

1.D)

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))

# Basic arithmetic operations


addition = num1 + num2
subtraction = num1 - num2
multiplication = num1 * num2
division = num1 / num2 if num2 != 0 else "Undefined (division by zero)"
modulus = num1 % num2 if num2 != 0 else "Undefined (modulus by zero)"

# Results
print(f"The sum of {num1} and {num2} is: {addition}")
print(f"The difference of {num1} and {num2} is: {subtraction}")
print(f"The product of {num1} and {num2} is: {multiplication}")
print(f"The division of {num1} by {num2} is: {division}")
print(f"The modulus of {num1} and {num2} is: {modulus}")
Experiment 2

Q.1) Develop a Python program to manage a task list using lists and tuples,
including adding, removing, updating, and sorting tasks.

#List
task = ['task1', 'task2', 'task3']
print(task)

print("----------Add---------------")
task.append('task10')
print(task)
task.insert(0, 'task50')
print(task)
task.extend(['task11', 'task12'])
print(task)
task[0] = 'task20'
print(task)

print("----------Delete---------------")
task.remove('task1')
print(task)
del_item = task.pop(1)
print(del_item)
del task[0]
print(task)

print("----------Repetition-------------")
task = task * 3
print(task)

print("----------Select--------------")
print(task[0])
print(task[-1])
Tuple:

tup = (4, 1, 2, 3, 6)
tup_name = ( 'c','a', 'b', 'd')

print(tup)
print(tup_name)

print("----------Sort--------------")
sort = sorted(tup)
print(sort)
sort_var = sorted(tup_name)
print(sort_var)

print("----------Reverse--------------")
rev_sort_var = sorted(tup_name, reverse=True)
print(rev_sort_var)
rev_sort = sorted(tup, reverse=True)
print(rev_sort)

Q.2) 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.

# Create sets of students enrolled in different entrance exams


cet_students = {"John", "Alice", "Bob", "David", "Eve"}
jee_students = {"Alice", "Bob", "Charlie", "David", "Grace"}
neet_students = {"Eve", "Grace", "Charlie", "Fay", "Hank"}

# 1. Union of sets: Students appearing for any of the exams (CET, JEE, or
NEET)
all_students = cet_students.union(jee_students, neet_students)
print("Students appearing for any exam (CET, JEE, NEET):")
print(all_students)

# 2. Intersection of sets: Students appearing for all three exams (CET,


JEE, NEET)
students_in_all_exams = cet_students.intersection(jee_students,
neet_students)
print("\nStudents appearing for all three exams (CET, JEE, NEET):")
print(students_in_all_exams)

# 3. Difference of sets: Students enrolled in CET but not in JEE or NEET


cet_only_students = cet_students.difference(jee_students, neet_students)
print("\nStudents enrolled only in CET:")
print(cet_only_students)

# 4. Symmetric Difference of sets: Students enrolled in either CET, JEE,


or NEET but not in both
exclusive_students =
cet_students.symmetric_difference(jee_students).symmetric_difference(neet_
students)
print("\nStudents appearing in only one of the exams (CET, JEE, or NEET,
but not both):")
print(exclusive_students)

Q.3) Write a Python program to create, update, and manipulate a dictionary of student
records, including their grades and attendance.

'''
Write a Python program to create, update, and manipulate a
dictionary of student records, including their grades and attendance.
'''
print("---------------dictionaries----------------------")
dictionaries = {"roll" : 1, "Name" : "A", "Year" : "SE", "Age": 20}
print(dictionaries)

print(type(dictionaries))
print("length of dict is : ", len(dictionaries))
print(dictionaries.keys())
print(dictionaries.values())

print("-------------access an item-------------------")

print(dictionaries['roll'])
print(dictionaries.get("Name"))
print("-------------update/add-------------------")

dictionaries['grade'] = "A"
print("Add new element: ", dictionaries)

dictionaries['Attendance'] = "30%"
print("Update dictionary : ", dictionaries)

dictionaries.update(occupation = "software developer")


print(dictionaries)

print("-------------Update-------------------")
dictionaries["Age"]=25
print(dictionaries)

print("-------------delete-------------------")

dictionaries.pop("occupation")
print(dictionaries)

del dictionaries['Age']
print(dictionaries)

You might also like