21EC014 Final Assignment
21EC014 Final Assignment
1) WAP to display basic details of a User like Name, Roll no, Division and
Address.
➢ def personal_details():
name , age = ‘ Sa ’ , 20
address = ‘ Vadodara , india ’
print(‘ Name: { }\nAge: { }\nAddress: { }’.format(name , age,
address ))
personal details()
1
EC 1 21EC014
5) WAP to convert distance from C.M. into meter, KM., feet, and inches.
➢ cm = int(input("Enter the cm value : "))
➢ meter = cm / 100.0;
➢ kilometer = cm / 100000.0;
➢ feet = cm / 30.48;
➢ inch = cm * 0.393701;
➢ print("Length in meter = " ,
➢ meter , "m");
➢ print("Length in Kilometer = ",
➢ kilometer , "km");
➢ print("Length in Feet = ",
2
EC 1 21EC014
➢ feet , "feet");
➢ print("Length in Inch = ",
➢ inch , "inch");
3
EC 1 21EC014
➢ avg = total/num
➢ print('Average of ', num, ' numbers is :', avg)
if num < 0:
print("Factorial does not exist for negative numbers")
elif num == 0:
print("Factorial of 0 is 1")
else:
for i in range(1, num + 1):
factorial = factorial * i
print("Factorial of", num, "is", factorial)
4
EC 1 21EC014
12) WAP that demonstrates the use of break and continue statements
to alter the flow of the loop.
➢ # Example of break statement
➢ for i in range(1, 11):
➢ if i == 5:
➢ break # Exit the loop when i equals 5
➢ print(i)
➢ # Example of continue statement
➢ for i in range(1, 11):
➢ if i == 5:
➢ continue # Skip printing 5 and continue with the next iteration
➢ print( i )
13) WAP to prompt the user for hours and rate per hour to compute
gross
pay. Company will give the employee 1.5 times the Hourly rate for hours
worked above 40 hours.
➢ hours = float(input(“quot;Enter the number of hours worked: “quot;))
rate = float(input(“quot;Enter the hourly rate: “quot;))
if hours “gt; 40:
overtime_hours = hours - 40
overtime_rate = rate * 1.5
gross_pay = (40 * rate) + (overtime_hours * overtime_rate)
else:
gross_pay = hours * rate
print(“quot;Gross pay: $”quot;, gross_pay)
14) Given the family relationship below output all persons who fit in
theinput characteristic. These characteristics are SIBLING, PARENT,
CHILD,
5
EC 1 21EC014
Family 2-> Debbie and Phil have children Jill and Betty. Jill and Frank
have child Sarah. Betty and Paul have children Marry, Jane and Bart.
➢ Family 1
family1 = {
“quot;Ann”quot;: [“quot;Bill”quot;, “quot;Cathy”quot;, “quot;Frank”quot;],
“quot;Marty”quot;: [“quot;Bill”quot;, “quot;Cathy”quot;, “quot;Frank”quot;],
“quot;Cathy”quot;: [“quot;Madd”quot;, “quot;Sally”quot;],
“quot;Don”quot;: [“quot;Madd”quot;, “quot;Sally”quot;],
“quot;Frank”quot;: [“quot;Sarah”quot;],
“quot;Jill”quot;: [“quot;Sarah”quot;]
}
# Family 2
family2 = {
“quot;Debbie”quot;: [“quot;Jill”quot;, “quot;Betty”quot;],
“quot;Phil”quot;: [“quot;Jill”quot;, “quot;Betty”quot;],
“quot;Jill”quot;: [“quot;Sarah”quot;],
“quot;Frank”quot;: [“quot;Sarah”quot;],
“quot;Betty”quot;: [“quot;Marry”quot;, “quot;Jane”quot;, “quot;Bart”quot;],
“quot;Paul”quot;: [“quot;Marry”quot;, “quot;Jane”quot;, “quot;Bart”quot;]
}
# Function to find all siblings
def find_siblings(person, family):
6
EC 1 21EC014
siblings = []
for parent, children in family.items():
if person in children and len(children) “gt; 1:
siblings += [sibling for sibling in children if sibling != person]
return siblings
7
EC 1 21EC014
return grandparents
8
EC 1 21EC014
15) WAP which will print a string as it is except # and done is entered.
input_string = ""
while True:
9
EC 1 21EC014
18) WAP to find the largest and smallest value in a list or sequence.
➢ my_list = [10, 20, 30, 40, 50]
# Using the min() and max() functions to find the smallest and largest
value
smallest_value = min(my_list)
largest_value = max(my_list)
print("Smallest Value:", smallest_value)
print("Largest Value:", largest_value)
10
EC 1 21EC014
b = temp
return (a, b)
12
EC 1 21EC014
# Example usage
x=5
y = 10
print("Before Swap: x =", x, "and y =", y)
x, y = swap(x, y)
print("After Swap: x =", x, "and y =", y)
24) WAP read a set of numbers from keyboard & to find the sum
of all
elements of the given array using a function.
➢ def find_sum(numbers):
sum = 0
13
EC 1 21EC014
print("b =", b)
print("c =", c)
print("d =", d)
# Calling the function with positional arguments
my_function(1, 2)
# Calling the function with keyword arguments
my_function(a=1, b=2, c=3, d=4)
# Calling the function with mixed arguments
14
EC 1 21EC014
26) WAP to implement take a break story. This program will notify
users to
take a break by playing their favorite video on YouTube after fixed
amount of time.
➢ import time
import webbrowser
# Function to play the favorite video on YouTube
def play_video():
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
webbrowser.open_new_tab(url)
# Main function to implement the "Take a Break" story
def take_a_break(total_breaks, break_time):
count = 0
while count < total_breaks:
# Wait for the break time
time.sleep(break_time)
# Play the favorite video on YouTube
play_video()
count += 1
# Set the total number of breaks and the break time in seconds
total_breaks = 3
break_time = 60 * 60 # 1 hour
# Call the take_a_break function
15
EC 1 21EC014
take_a_break(total_breaks, break_time)
27) WAP to help weatherman who will predict weather for a particular
week
and for next seven days. Implement this scenario by creating two
modules namely daily.py and weekly.py for predicting daily and weekly
weather respectively.
➢ import random
28) Rewrite Spam confidence program (5.2) using try and except.
➢ fname = input("Enter file name: ")
try:
16
EC 1 21EC014
fhand = open(fname)
except:
print("File cannot be opened:", fname)
quit()
count = 0
total = 0
for line in fhand:
if line.startswith("X-DSPAM-Confidence:"):
count += 1
try:
confidence = float(line[line.find(":")+1:].strip())
total += confidence
except:
print("Error: could not convert confidence value to float")
if count > 0:
average = total / count
print("Average spam confidence:", average)
else:
print("No lines starting with 'X-DSPAM-Confidence:' were
found in
the file.")
29) WAP to read through the mail box data and when you find line
that starts
with “From”, you will split the line into words using the split function.
We are interested in who sent the message, which is the second word
on the From line.
17
EC 1 21EC014
19
EC 1 21EC014
turtle.exitonclick()
33) Create class namely Employee. And show the Employee name,
salary
and count using OOP concept.
➢ class Employee:
# class variable to keep track of the number of employees
count = 0
def __init__(self, name, salary):
self.name = name
self.salary = salary
Employee.count += 1
def displayEmployee(self):
print("Name : ", self.name, ", Salary: ", self.salary)
def displayCount(self):
print("Total Employees %d" % Employee.count)
20
EC 1 21EC014
def display(self):
print("Name:", self.name)
print("Salary:", self.salary)
class Qualification:
def __init__(self, qualification):
self.qualification = qualification
def display(self):
print("Qualification:", self.qualification)
class Scientist(Employee, Qualification):
def __init__(self, name, salary, qualification, field_of_study):
Employee.__init__(self, name, salary)
Qualification.__init__(self, qualification)
self.field_of_study = field_of_study
def display(self):
Employee.display(self)
Qualification.display(self)
print("Field of Study:", self.field_of_study)
21
EC 1 21EC014
22