Professional Documents
Culture Documents
15CSE337 Foundation of IT: Name: Gokula Krishnaa P Date: 04/03/2022 Roll No: CB - EN.U4EIE18017
15CSE337 Foundation of IT: Name: Gokula Krishnaa P Date: 04/03/2022 Roll No: CB - EN.U4EIE18017
Foundation of IT
Name: Gokula Krishnaa P Date: 04/03/2022
Roll no: CB.EN.U4EIE18017
Code:
class feet:
def __init__(self, d):
self.d = d
Output:
Code:
class complex:
def __init__(self,a,b,i):
self.x = a
self.y = b
self.i = i
def display(self):
print("complex number-{} is {}+i{}".format(self.i,self.x,self.y))
def __add__(self,other):
return self.x+other.x,self.y+other.y
i=int(1)
c1 = complex(2,3,i)
i+=1
c2 = complex(4,5,i)
c1.display()
c2.display()
c3 = c1+c2
print("complex number-3 is {}+i{}".format(c3[0],c3[1]))
Output:
Create a class called 'times' that has three integer data members for hours,
minutes and seconds,
define a member function to read the values, member operator function to
add time, member function to display time in HH:MM:SS format.
Write a main function to create two time objects, use operator function to
add them and display the results in HH:MM:SS format.
Input Format:
First 3 values of the sample input represents the hr, min, sec values of time 1,
next 3 values represents the hr, min, sec values of time 2.
Output Format:
Display the resultant time in HH:MM:SS format.
Sample Input:
time1=3:44:12
time2=2:12:13
time3=time1+time2 = 5:56:25
print(time1+time2)
Code:
class times:
def readvalues(self,i):
self.i = i
self.h = int(input("Enter hours for time{}:".format(self.i)))
self.m = int(input("Enter minutes for time{}:".format(self.i)))
self.s = int(input("Enter seconds for time{}:".format(self.i)))
def display(self):
print("time{}={}:{}:{}".format(self.i,self.h,self.m,self.s))
def __add__(self,other):
return other.i+1,self.h+other.h,self.m+other.m,self.s+other.s
i = int(1)
t1 = times()
t1.readvalues(i)
i+=1
t2 = times()
t2.readvalues(i)
t3=t1+t2
t3=list(t3)
while(t3[3]>60):
t3[2]+=1
t3[3]-=60
while(t3[2]>60):
t3[2]-=60
t3[1]+=1
print("time{}={}:{}:{}".format(t3[0],t3[1],t3[2],t3[3]))
Output:
4. Monthly Expense
Aim:
Option1: To check the total expenses in May Month is greater than June or
not. { Possible Outputs: TRUE/FALSE } -gt
Option2: To check the total expenses in May Month is lesser than June or
not. { Possible Outputs: TRUE/FALSE } -lt
Option3: To check the total expenses in May and June is equal or not.
{ Possible Outputs: TRUE/FALSE } -eq
Option4: To add and print the total expenses in the month of May and June
Month.
Main Program Template is given.
May=Monthlyexpense()
June=Monthlyexpense()
choice=int(input())
if (choice==1):
May>June
elif (choice==2):
May<June
elif (choice==3):
May==June
elif (choice==4):
May+June
...........................
case1:
Sample Input:
details for May month:
household exp:2000
emi exp: 3200
education expense: 500
details for June month:
household exp:1800
emi exp: 3200
education expense: 1000
option: 1
Sample Output:
FALSE
....................
case2:
Sample Input:
details for May month:
household exp:2000
emi exp: 3200
education expense:500
details for June month:
household exp:1800
emi exp: 3200
education expense:1000
option : 4
Sample Output:
11700