#1.chef code
a,b,a1,b1,a2,b2=map(int,input().split())
if (a==a1 or a==b1):
print(1)
elif (b==a2 or b==b2):
print(2)
else:
print(0)
1 2 3 3 2 3 2
#2. difficulty levels of the problems are A1,A2,A3,A4
difficulty_level=list(map(int,input().split()))
problem=set(difficulty_level) #set removes duplicates
print(problem)
if len(problem) ==2:
print(1)
elif len(problem) > 2:
print(len(problem) - 1)
else:
print(0)
1 2 3 4 {1, 2, 3, 4} 3
# 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)
from datetime import date
class display_date:
def __init__(self, date1):
self.date1=date1
def __eq__(self,other):
if self.date1==other.date1:
return "both dates are equal"
else:
return "both dates are not equal"
def __gt__(self, other):
if self.date1 > other.date1:
return "date1 is greater"
else:
return "date1 is not greater"
def __lt__(self, other):
if self.date1 < other.date1:
return "date2 is greater"
else:
return "date2 is not greater"
date1=date(2022,12,4)
date2=date(2022,12,3)
d1=display_date(date1)
d2=display_date(date2)
print(d1 == d2)
print(d1 > d2)
print(d1 < d2)
both dates are not equal date1 is greater date2 is not greater
#4. Develop python code to add, subtract , multiply and divide two distances where each distance contains two things of the format KM followed by Meters.
import math
class operations:
def __int__(self,d1,d2):
self.d1=d1
self.d2=d2
def add(self,d1,d2):
res=d1+d2
x1=math.modf(res/1000)
dec1,num1=x1
print("total distance is",num1 ,"kms",dec1*1000,"meters")
def sub(self,d1,d2):
res=d1-d2
x2=math.modf(res/1000)
dec2,num2=x2
print("total distance is",num2 ,"kms",dec2*1000,"meters")
def mul(self,d1,d2):
res=d1*d2
x3=math.modf(res/1000)
dec3,num3=x3
print("total distance is",num3 ,"kms",dec3*1000,"meters")
def div(self,d1,d2):
res=d1/d2
x4=math.modf(res/1000)
dec4,num4=x4
print("total distance is",num4 ,"kms",dec4*1000,"meters")
distance1=float(input("Enter distances in Kilometers:"))
m1=float(input("Enter meters:"))
distance2=float(input("Enter distances in Kilometers"))
m2=float(input("Enter meters:"))
k1_to_m1=distance1 * 1000
final_dist1=k1_to_m1 + m1
k2_to_m2=distance2 * 1000
final_dist2=k2_to_m2 + m2
result=operations()
result.add(final_dist1,final_dist2)
result.sub(final_dist1,final_dist2)
result.mul(final_dist1,final_dist2)
result.div(final_dist1,final_dist2)
Enter distances in Kilometers:2000 Enter meters:30 Enter distances in Kilometers40 Enter meters:34 total distance is 2040.0 kms 64.00000000007822 meters total distance is 1959.0 kms 996.0000000000946 meters total distance is 80069201.0 kms 19.999995827674866 meters total distance is 0.0 kms 49.95828545736124 meters
#5.Develop a class called Box with attributes length, breadth, depth and define required constructor and other relevant methods. Inherit Box class to WeightBox which contains extra attribute as weight. From this extent further as ColorWeightBox which has Color as extra attribute. Develop code for entire scenario using multi-level inheritance.
class Box:
def __init__(self,l,b,d):
self.l=l
self.b=b
self.d=d
def display(self):
print("Lenght:",self.l)
print("Breadth:",self.b)
print("Depth:",self.d)
class WeightBox(Box):
def __init__(self,l,b,d,w):
Box.__init__(self,l,b,d)
self.w=w
def display(self):
Box.display(self)
print("Weight:",self.w)
class ColorWeightBox(WeightBox):
def __init__(self,l,b,d,w,c):
WeightBox.__init__(self,l,b,d,w)
self.c=c
def display(self):
WeightBox.display(self)
print("Color:",self.c)
b1 = Box(10,3,45)
b1.display()
b2=WeightBox(10,3,45,234)
b2.display()
b3=ColorWeightBox(10,3,45,234,"PINK")
b3.display()
Lenght: 10 Breadth: 3 Depth: 45 Lenght: 10 Breadth: 3 Depth: 45 Weight: 234 Lenght: 10 Breadth: 3 Depth: 45 Weight: 234 Color: PINK