Skip to content

Commit 6ccd778

Browse files
Add files via upload
1 parent c660574 commit 6ccd778

File tree

8 files changed

+307
-0
lines changed

8 files changed

+307
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Student:
2+
def __init__(self, name="Just a student", dept="nothing"):
3+
self.__name = name
4+
self.__department = dept
5+
6+
def set_department(self, dept):
7+
self.__department = dept
8+
9+
def get_name(self):
10+
return self.__name
11+
12+
def set_name(self, name):
13+
self.__name = name
14+
15+
def __str__(self):
16+
return "Name: " + self.__name + " Department: " + self.__department
17+
18+
19+
class BBA_Student(Student):
20+
def __init__(self, name="default", dept="BBA"):
21+
super().__init__(name, dept)
22+
23+
24+
print(BBA_Student())
25+
print(BBA_Student("Humpty Dumpty"))
26+
print(BBA_Student("Little Bo Peep"))
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
class Vehicle: # review
2+
def __init__(self):
3+
self.x = 0
4+
self.y = 0
5+
6+
def moveUp(self):
7+
self.y += 1
8+
9+
def moveDown(self):
10+
self.y -= 1
11+
12+
def moveRight(self):
13+
self.x += 1
14+
15+
def moveLeft(self):
16+
self.x -= 1
17+
18+
def __str__(self):
19+
return "(" + str(self.x) + " , " + str(self.y) + ")"
20+
21+
22+
class Vehicle2010(Vehicle):
23+
def moveLowerLeft(self):
24+
super().moveDown()
25+
super().moveLeft()
26+
27+
def equals(self, other):
28+
return self.x == other.x and self.y == other.y
29+
30+
31+
print("Part 1")
32+
print("------")
33+
car = Vehicle()
34+
print(car)
35+
car.moveUp()
36+
print(car)
37+
car.moveLeft()
38+
print(car)
39+
car.moveDown()
40+
print(car)
41+
car.moveRight()
42+
print(car)
43+
print("------")
44+
print("Part 2")
45+
print("------")
46+
car1 = Vehicle2010()
47+
print(car1)
48+
car1.moveLowerLeft()
49+
print(car1)
50+
car2 = Vehicle2010()
51+
car2.moveLeft()
52+
print(car1.equals(car2))
53+
car2.moveDown()
54+
print(car1.equals(car2))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class Tournament: # review
2+
def __init__(self, name="Default"):
3+
self.__name = name
4+
5+
def set_name(self, name):
6+
self.__name = name
7+
8+
def get_name(self):
9+
return self.__name
10+
11+
12+
class Cricket_Tournament(Tournament):
13+
def __init__(self, name=None, teams=0, type="No type"):
14+
self.teams = teams
15+
self.type = type
16+
self.name = name
17+
18+
if self.name == None:
19+
self.name = super().__init__()
20+
else:
21+
self.name = super().__init__(name)
22+
23+
def detail(self):
24+
name = super().get_name()
25+
return f"Cricket Tournament Name: {name}\nNumber of Teams: {self.teams}\nType: {self.type}"
26+
27+
28+
class Tennis_Tournament(Tournament):
29+
def __init__(self, name, player_num):
30+
self.name = name
31+
self.player_num = player_num
32+
33+
def detail(self):
34+
return (
35+
f"Tennis Tournamnet Name: {self.name}\nNumber of Players: {self.player_num}"
36+
)
37+
38+
39+
ct1 = Cricket_Tournament()
40+
print(ct1.detail())
41+
print("-----------------------")
42+
ct2 = Cricket_Tournament("IPL", 10, "t20")
43+
print(ct2.detail())
44+
print("-----------------------")
45+
tt = Tennis_Tournament("Roland Garros", 128)
46+
print(tt.detail())
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
class Product:
2+
def __init__(self, id, title, price):
3+
self.__id = id
4+
self.__title = title
5+
self.__price = price
6+
7+
def get_id_title_price(self):
8+
return (
9+
"ID: "
10+
+ str(self.__id)
11+
+ " Title: "
12+
+ self.__title
13+
+ " Price: "
14+
+ str(self.__price)
15+
)
16+
17+
18+
class Book(Product):
19+
def __init__(self, id, title, price, ISBN, publisher):
20+
super().__init__(id, title, price)
21+
self.ISBN = ISBN
22+
self.publisher = publisher
23+
24+
def printDetail(self):
25+
return (
26+
super().get_id_title_price()
27+
+ f"\nISBN: {self.ISBN} Publisher: {self.publisher}"
28+
)
29+
30+
31+
class CD(Product):
32+
def __init__(self, id, title, price, band, duration, genre):
33+
super().__init__(id, title, price)
34+
self.band = band
35+
self.duration = duration
36+
self.genre = genre
37+
38+
def printDetail(self):
39+
return (
40+
super().get_id_title_price()
41+
+ f"\nBand: {self.band} Duration: {self.duration}minutes\nGenre: {self.genre}"
42+
)
43+
44+
45+
book = Book(1, "The Alchemist", 500, "97806", "HarperCollins")
46+
print(book.printDetail())
47+
print("-----------------------")
48+
cd = CD(2, "Shotto", 300, "Warfaze", 50, "Hard Rock")
49+
print(cd.printDetail())
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Animal:
2+
def __init__(self, sound):
3+
self.__sound = sound
4+
5+
def makeSound(self):
6+
return self.__sound
7+
8+
9+
class Printer:
10+
def printSound(self, a):
11+
print(a.makeSound())
12+
13+
14+
class Dog(Animal):
15+
def __init__(self, sound):
16+
super().__init__(sound)
17+
18+
19+
class Cat(Animal):
20+
def __init__(self, sound):
21+
super().__init__(sound)
22+
23+
24+
# write your code here
25+
d1 = Dog("bark")
26+
c1 = Cat("meow")
27+
a1 = Animal("Animal does not make sound")
28+
pr = Printer()
29+
pr.printSound(a1)
30+
pr.printSound(c1)
31+
pr.printSound(d1)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
class Shape:
2+
def __init__(self, name="Default", height=0, base=0):
3+
self.area = 0
4+
self.name = name
5+
self.height = height
6+
self.base = base
7+
8+
def get_height_base(self):
9+
return "Height: " + str(self.height) + ", Base: " + str(self.base)
10+
11+
12+
class triangle(Shape):
13+
def calcArea(self):
14+
self.area = (self.height * self.base) / 2
15+
16+
def printDetail(self):
17+
18+
return (
19+
f"Shape name: {self.name}\n"
20+
+ super().get_height_base()
21+
+ f"\nArea: {self.area}"
22+
)
23+
24+
25+
class trapezoid(Shape):
26+
def __init__(self, name, height, base, side_A):
27+
super().__init__(name, height, base)
28+
self.side_A = side_A
29+
30+
def calcArea(self):
31+
self.area = ((self.base + self.side_A) / 2) * self.height
32+
33+
def printDetail(self):
34+
return (
35+
f"Shape name: {self.name}\n"
36+
+ super().get_height_base()
37+
+ f", Side_A: {self.side_A}"
38+
+ f"\nArea: {self.area}"
39+
)
40+
41+
42+
tri_default = triangle()
43+
tri_default.calcArea()
44+
print(tri_default.printDetail())
45+
print("--------------------------")
46+
tri = triangle("Triangle", 10, 5)
47+
tri.calcArea()
48+
print(tri.printDetail())
49+
print("---------------------------")
50+
trap = trapezoid("Trapezoid", 10, 6, 4)
51+
trap.calcArea()
52+
print(trap.printDetail())
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
class Football:
2+
def __init__(self, team_name, name, role):
3+
self.__team = team_name
4+
self.__name = name
5+
self.role = role
6+
self.earning_per_match = 0
7+
8+
def get_name_team(self):
9+
return "Name: " + self.__name + ", Team Name: " + self.__team
10+
11+
12+
class Player(Football):
13+
def __init__(self, team_name, name, role, goal, played):
14+
super().__init__(team_name, name, role)
15+
self.goal = goal
16+
self.played = played
17+
18+
def calculate_ratio(self):
19+
self.ratio = self.goal / self.played
20+
21+
def print_details(self):
22+
earning = (self.goal * 1000) + (self.played * 10)
23+
print(super().get_name_team())
24+
print(f"Team Role: {self.role}")
25+
print(f"Total Goal: {self.goal}, Total Played: {self.played}")
26+
print(f"Goal Ratio: {self.ratio}")
27+
print(f"Match Earning: {earning}K")
28+
29+
30+
class Manager(Football):
31+
def __init__(self, team_name, name, role, win):
32+
super().__init__(team_name, name, role)
33+
self.win = win
34+
35+
def print_details(self):
36+
earning = self.win * 1000
37+
print(super().get_name_team())
38+
print(f"Team Role: {self.role}")
39+
print(f"Win: {self.win}")
40+
print(f"Match Earning: {earning}K")
41+
42+
43+
player_one = Player("Juventus", "Ronaldo", "Striker", 25, 32)
44+
player_one.calculate_ratio()
45+
player_one.print_details()
46+
print("------------------------------------------")
47+
manager_one = Manager("Real Madrid", "Zidane", "Manager", 25)
48+
manager_one.print_details()

0 commit comments

Comments
 (0)