Skip to content

Commit fd6d1b4

Browse files
Add files via upload
1 parent 2827c38 commit fd6d1b4

File tree

9 files changed

+855
-0
lines changed

9 files changed

+855
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Marks:
2+
def __init__(self, mark):
3+
self.mark = mark
4+
5+
def __add__(self, other):
6+
sum = self.mark + other.mark
7+
return Marks(sum)
8+
9+
10+
Q1 = Marks(int(input("Quiz 1 (out of 10): ")))
11+
Q2 = Marks(int(input("Quiz 2 (out of 10): ")))
12+
Lab = Marks(int(input("Lab (out of 30): ")))
13+
Mid = Marks(int(input("Mid (out of 20): ")))
14+
Final = Marks(int(input("Final (out of 30): ")))
15+
total = Q1 + Q2 + Lab + Mid + Final
16+
print("Total marks: {}".format(total.mark))
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
class Teacher:
2+
def __init__(self, name, sub):
3+
self.__name = name
4+
self.__sub = sub
5+
self.__p = []
6+
7+
def addCourse(self, now):
8+
self.__p.append(now.course)
9+
10+
def printDetail(self):
11+
print("====================================")
12+
print("Name:", self.__name)
13+
print("Department:", self.__sub)
14+
print("List of courses")
15+
print("====================================")
16+
for i in self.__p:
17+
print(i)
18+
print("====================================")
19+
20+
21+
class Course:
22+
def __init__(self, course):
23+
self.course = course
24+
25+
26+
t1 = Teacher("Saad Abdullah", "CSE")
27+
t2 = Teacher("Mumit Khan", "CSE")
28+
t3 = Teacher("Sadia Kazi", "CSE")
29+
c1 = Course("CSE 110 Programming Language I")
30+
c2 = Course("CSE 111 Programming Language-II")
31+
c3 = Course("CSE 220 Data Structures")
32+
c4 = Course("CSE 221 Algorithms")
33+
c5 = Course("CCSE 230 Discrete Mathematics")
34+
c6 = Course("CSE 310 Object Oriented Programming")
35+
c7 = Course("CSE 320 Data Communications")
36+
c8 = Course("CSE 340 Computer Architecture")
37+
t1.addCourse(c1)
38+
t1.addCourse(c2)
39+
t2.addCourse(c3)
40+
t2.addCourse(c4)
41+
t2.addCourse(c5)
42+
t3.addCourse(c6)
43+
t3.addCourse(c7)
44+
t3.addCourse(c8)
45+
t1.printDetail()
46+
t2.printDetail()
47+
t3.printDetail()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class Team:
2+
def __init__(self, name=None):
3+
self.__name = name
4+
self.__li = []
5+
6+
def setName(self, name):
7+
if self.__name == None:
8+
self.__name = name
9+
10+
def addPlayer(self, name):
11+
self.__li.append(name.player)
12+
13+
def printDetail(self):
14+
print("=====================")
15+
print("Team: ", self.__name)
16+
print("List of players: ")
17+
print(self.__li)
18+
print("=====================")
19+
20+
21+
class Player:
22+
def __init__(self, player):
23+
self.player = player
24+
25+
26+
b = Team()
27+
b.setName("Bangladesh")
28+
mashrafi = Player("Mashrafi")
29+
b.addPlayer(mashrafi)
30+
tamim = Player("Tamim")
31+
b.addPlayer(tamim)
32+
b.printDetail()
33+
a = Team("Australia")
34+
ponting = Player("Ponting")
35+
a.addPlayer(ponting)
36+
lee = Player("Lee")
37+
a.addPlayer(lee)
38+
a.printDetail()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Color:
2+
def __init__(self, color):
3+
self.clr = color
4+
5+
def __add__(self, other):
6+
self.clr = self.clr + other.clr
7+
8+
if self.clr == "redyellow" or self.clr == "yellowred":
9+
self.clr = "Orange"
10+
elif self.clr == "redblue" or self.clr == "bluered":
11+
self.clr = "Violet"
12+
elif self.clr == "yellowblue" or self.clr == "blueyellow":
13+
self.clr = "Green"
14+
15+
return Color(self.clr)
16+
17+
18+
C1 = Color(input("First Color: ").lower())
19+
C2 = Color(input("Second Color: ").lower())
20+
C3 = C1 + C2
21+
print("Color formed:", C3.clr)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import math
2+
3+
4+
class Circle:
5+
def __init__(self, radius=None):
6+
self.radius = radius
7+
8+
def getRadius(self):
9+
return self.radius
10+
11+
def setRadius(self, radius):
12+
self.radius = radius
13+
return self.radius
14+
15+
def area(self):
16+
self.area = (math.pi) * self.radius * self.radius
17+
return self.area
18+
19+
def __add__(self, other):
20+
return Circle(self.radius + other.radius)
21+
22+
23+
c1 = Circle(4)
24+
print("First circle radius:", c1.getRadius())
25+
print("First circle area:", c1.area())
26+
27+
c2 = Circle(5)
28+
print("Second circle radius:", c2.getRadius())
29+
print("Second circle area:", c2.area())
30+
31+
c3 = c1 + c2
32+
print("Third circle radius:", c3.getRadius())
33+
print("Third circle area:", c3.area())
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class Triangle:
2+
def __init__(self, base=None, height=None):
3+
self.__base = base
4+
self.__height = height
5+
6+
def getBase(self):
7+
return self.__base
8+
9+
def setBase(self, base):
10+
self.__base = base
11+
return self.__base
12+
13+
def getHeight(self):
14+
return self.__height
15+
16+
def setHeight(self, height):
17+
self.__height = height
18+
return self.__height
19+
20+
def area(self):
21+
self.area = 0.5 * self.__base * self.__height
22+
return self.area
23+
24+
def __sub__(self, other):
25+
self.new_base = self.__base - other.__base
26+
self.new_height = self.__height - other.__height
27+
return Triangle(self.new_base, self.new_height)
28+
29+
30+
t1 = Triangle(10, 5)
31+
print("First Triangle Base:", t1.getBase())
32+
print("First Triangle Height:", t1.getHeight())
33+
print("First Triangle area:", t1.area())
34+
35+
t2 = Triangle(5, 3)
36+
print("Second Triangle Base:", t2.getBase())
37+
print("Second Triangle Height:", t2.getHeight())
38+
print("Second Triangle area:", t2.area())
39+
40+
t3 = t1 - t2
41+
print("Third Triangle Base:", t3.getBase())
42+
print("Third Triangle Height:", t3.getHeight())
43+
print("Third Triangle area:", t3.area())
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
class Dolls:
2+
def __init__(self, name, price):
3+
self.name = name
4+
self.price = price
5+
6+
def detail(self):
7+
lst = self.name.split()
8+
9+
if len(lst) <= 2:
10+
return f"Doll: {self.name} \nTotal price: {str(self.price)} taka"
11+
else:
12+
return f"Dolls: {self.name} \nTotal price: {str(self.price)} taka"
13+
14+
def __gt__(self, other):
15+
if self.price > other.price:
16+
return True
17+
else:
18+
return False
19+
20+
def __add__(self, other):
21+
var1 = self.price + other.price
22+
var2 = self.name + " " + other.name
23+
return Dolls(var2, var1)
24+
25+
26+
obj_1 = Dolls("Tweety", 2500)
27+
print(obj_1.detail())
28+
if obj_1 > obj_1:
29+
print("Congratulations! You get the Tweety as a gift!")
30+
else:
31+
print("Thank you!")
32+
33+
print("=========================")
34+
obj_2 = Dolls("Daffy Duck", 1800)
35+
print(obj_2.detail())
36+
if obj_2 > obj_1:
37+
print("Congratulations! You get the Tweety as a gift!")
38+
else:
39+
print("Thank you!")
40+
41+
print("=========================")
42+
obj_3 = Dolls("Bugs Bunny", 3000)
43+
print(obj_3.detail())
44+
if obj_3 > obj_1:
45+
print("Congratulations! You get the Tweety as a gift!")
46+
else:
47+
print("Thank you!")
48+
49+
print("=========================")
50+
obj_4 = Dolls("Porky Pig", 1500)
51+
print(obj_4.detail())
52+
if obj_4 > obj_1:
53+
print("Congratulations! You get the Tweety as a gift!")
54+
else:
55+
print("Thank you!")
56+
57+
print("=========================")
58+
obj_5 = obj_2 + obj_3
59+
print(obj_5.detail())
60+
if obj_5 > obj_1:
61+
print("Congratulations! You get the Tweety as a gift!")
62+
else:
63+
print("Thank you!")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# task-8
2+
class Coordinates:
3+
def __init__(self, x_axis, y_axis):
4+
self.x_axis = x_axis
5+
self.y_axis = y_axis
6+
7+
def detail(self):
8+
return (self.x_axis, self.y_axis)
9+
10+
def __sub__(self, other):
11+
a = self.x_axis - other.x_axis
12+
b = self.y_axis - other.y_axis
13+
return Coordinates(a, b)
14+
15+
def __mul__(self, other):
16+
c = self.x_axis * other.x_axis
17+
d = self.y_axis * other.y_axis
18+
return Coordinates(c, d)
19+
20+
def __eq__(self, other):
21+
if self.x_axis == other.x_axis:
22+
return "The calculated coordinates are the same."
23+
else:
24+
return "The calculated coordinates are NOT the same."
25+
26+
27+
p1 = Coordinates(int(input()), int(input()))
28+
p2 = Coordinates(int(input()), int(input()))
29+
p4 = p1 - p2
30+
print(p4.detail())
31+
p5 = p1 * p2
32+
print(p5.detail())
33+
point_check = p4 == p5
34+
print(point_check)

0 commit comments

Comments
 (0)