Assignment#6 : Mohammed Abdul Wasay
#Explanation: chef has to use a language with two features A and B
#case 1: if first language has the required features of A1 & B1 that match with features A and B, then print 1
#case 2: if second language has the required features of A2 and B2 that match with features A and B, then print 2
#case 3: Neither language features match with A and B hence cannot switch to either language, then print 0
A,B,A1,B1,A2,B2 = map(int,input("Enter A,B,A1,B1,A2,B2:").split())
if(A1==A and B1==B): # test case with features A1 & B1 matching A & B
print("1","first language")
elif(A2==A and B2==B): # test case with features A2 & B2 matching A & B
print("2","second language")
else: # test case with features A2 & B1 or B2 & A1 not matching A & B
print("0","cannot switch to either language")
Enter A,B,A1,B1,A2,B2:2 4 2 4 3 1 1 first language
#There will be two special cases :
# All problems with distinct output will be 2
# All problems with same output will be 0
A1,B1,A2,B2 = map(int,input("Enter A1,B1,A2,B2:").split())
l = (A1, B1, A2, B2)
a=set(l)
print(l)
print(a)
if (len(a) == 4):
print(2)
elif (len(a) == 3):
print(2)
elif (len(a) == 2):
print(1)
else:
print(0)
Enter A1,B1,A2,B2:1 2 1 2 (1, 2, 1, 2) {1, 2} 1
3.Develop a python code to check given two dates d1 and d1 , check whether d1 is less than d2 or d1 is greater than d2 or d1 is equal to d2. (Hint: overload < , > , == operators)
# importing datetime module
import datetime
def compdates():
# date in yyyy/mm/dd format
date1= input('Enter a first date in YYYY/MM/DD format: ') #input(datetime.date)
date2 = input('Enter a second date in YYYY/MM/DD format: ') #input(datetime.date)
year1, month1, day1 = map(int, date1.split('/'))
year2, month2, day2 = map(int, date2.split('/'))
if year1 > year2: # date1 year is greater
print("d1 is greater than d2")
elif year1 < year2: # date2 year is greater
print("d1 is less than d2")
elif year1 == year2: # year is same for both dates
if month1 > month2:
print("d1 is greater than d2")
elif month1 < month2:
print("d2 is greater than d1")
else:
if day1 > day2:
print("d1 is greater than d2")
elif day1 < day2:
print("d1 is lesser than d2")
else:
print("d1 is equal to d2")
class CalculateDist:
def GetDistance(self):
self.km = int(input("Enter KM: "))
self.m= int(input("Enter M: "))
def PutDistance(self):
print(self.km,self.m)
def __add__(self, T):
R = CalculateDist()
R.m = self.m + T.m
R.km = self.km + T.km
R.km = R.km + (R.m//1000)
R.m = R.m % 1000
return R
def __sub__(self, T):
R = CalculateDist()
R.m = self.m - T.m
R.km = self.km - T.km
R.km = R.km + (R.m//1000)
R.m = R.m % 1000
return R
def __mult__(self, T):
R = CalculateDist()
R.m = self.m * T.m
R.km = self.km * T.km
R.km = R.km + (R.m//1000)
R.m = R.m % 1000
return R
def __div__(self, T):
R = CalculateDist()
R.m = self.m/T.m
R.km = self.km/T.km
R.km = R.km + (R.m//1000)
R.m = R.m % 1000
return R
D1 = CalculateDist()
D2 = CalculateDist()
print("Enter first distance")
D1.GetDistance()
print("Enter second distance")
D2.GetDistance()
D3 = D1+D2
print("Result of addition of both distance is")
D3.PutDistance()
D4 = D1-D2
print("Result of substraction of both distance is")
D4.PutDistance()
D5 = D1*D2
print("Result of multiplication of both distance is")
D5.PutDistance()
D6 = D1/D2
print("Result of division of both distance is")
D6.PutDistance()
Enter first distance Enter KM: 4 Enter M: 500 Enter second distance Enter KM: 3 Enter M: 200 Result of addition of both distance is 7 700 Result of substraction of both distance is 1 300
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-7-f27a76f799cf> in <module> 56 D4.PutDistance() 57 ---> 58 D5 = D1*D2 59 print("Result of multiplication of both distance is") 60 D5.PutDistance() TypeError: unsupported operand type(s) for *: 'CalculateDist' and 'CalculateDist'
class Box:
def __init__(self, lengt, breadt, dept):
self.lengt = lengt
self.breadt = breadt
self.dept = dept
def display(self):
print("LENGTH : ", self.lengt)
print("BREADTH : ", self.breadt)
print("DEPTH : ", self.dept)
class WeightBox(Box):
def __init__(self, lengt, breadt, dept, weight):
Box.__init__(self, lengt, breadt, dept)
self.weight = weight
def displayData(self):
Box.display(self)
print("WEIGHT : ", self.weight)
class ColorBox(Box):
def __init__(self, lengt, breadt, dept, color):
Box.__init__(self, lengt, breadt, dept)
self.color = color
def displayData(self):
Box.display(self)
print("COLOR : ", self.color)
print("*****WeightBox*****")
W=WeightBox(20, 15, 5, 20)
W.displayData()
print("*****ColorBox*****")
C=ColorBox(15, 10, 5, "red")
C.displayData()
*****WeightBox***** LENGTH : 20 BREADTH : 15 DEPTH : 5 WEIGHT : 20 *****ColorBox***** LENGTH : 15 BREADTH : 10 DEPTH : 5 COLOR : red