Skip to content

Commit 2827c38

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

File tree

17 files changed

+1589
-0
lines changed

17 files changed

+1589
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class Calculator:
2+
def __init__(self, first_value, operator, second_value):
3+
print("Let's Calculate!")
4+
self.first_value = first_value
5+
self.operator = operator
6+
self.second_value = second_value
7+
8+
print(f"Value 1: {self.first_value}")
9+
print(f"Operator: {self.operator}")
10+
print(f"Value 2: {self.second_value}")
11+
12+
if self.operator == "+":
13+
Calculator.add(self)
14+
elif self.operator == "-":
15+
Calculator.subtract(self)
16+
elif self.operator == "*":
17+
Calculator.multiply(self)
18+
elif self.operator == "/":
19+
Calculator.divide(self)
20+
21+
def add(self):
22+
print(f"Result : {self.first_value + self.second_value}")
23+
24+
def subtract(self):
25+
print(f"Result : {self.first_value - self.second_value}")
26+
27+
def multiply(self):
28+
print(f"Result : {self.first_value * self.second_value}")
29+
30+
def divide(self):
31+
print(f"Result : {self.first_value / self.second_value}")
32+
33+
34+
first_value = int(input())
35+
operator = input()
36+
second_value = int(input())
37+
38+
calc = Calculator(first_value, operator, second_value)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Customer:
2+
def __init__(self, name):
3+
self.name = name
4+
5+
def greet(self, name=None):
6+
if name != None:
7+
print(f"Hello {name}!")
8+
else:
9+
print("Hello!")
10+
11+
def purchase(self, *item):
12+
print(f"{self.name}, you purchased {len(item)} items(s):")
13+
for i in item:
14+
print(i)
15+
16+
17+
customer_1 = Customer("Sam")
18+
customer_1.greet()
19+
customer_1.purchase("chips", "chocolate", "orange juice")
20+
print("-----------------------------")
21+
customer_2 = Customer("David")
22+
customer_2.greet("David")
23+
customer_2.purchase("orange juice")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Panda:
2+
def __init__(self, name, gender, age):
3+
self.name = name
4+
self.gender = gender
5+
self.age = age
6+
7+
def sleep(self, sleep_time = None):
8+
if sleep_time is None:
9+
return f"{self.name}'s duration is unknown thus should have only bamboo leaves"
10+
11+
elif sleep_time >= 3 and sleep_time <= 5:
12+
return f"{self.name} sleeps {sleep_time} hours daily and should have Mixed Veggies"
13+
14+
elif sleep_time >= 6 and sleep_time <= 8:
15+
return f"{self.name} sleeps {sleep_time} hours daily and should have Eggplant & Tofu"
16+
17+
elif sleep_time >= 9 and sleep_time <= 11:
18+
return f"{self.name} sleeps {sleep_time} hours daily and should have Broccoli Chicken"
19+
20+
21+
panda1 = Panda("Kunfu","Male", 5)
22+
panda2=Panda("Pan Pan","Female",3)
23+
panda3=Panda("Ming Ming","Female",8)
24+
print("{} is a {} Panda Bear who is {} years old".format(panda1.name,panda1.gender,panda1.age))
25+
print("{} is a {} Panda Bear who is {} years old".format(panda2.name,panda2.gender,panda2.age))
26+
print("{} is a {} Panda Bear who is {} years old".format(panda3.name,panda3.gender,panda3.age))
27+
print("===========================")
28+
print(panda2.sleep(10))
29+
print(panda1.sleep(4))
30+
print(panda3.sleep())
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Cat:
2+
def __init__(self, color="White", activity="sitting"):
3+
self.color = color
4+
self.activity = activity
5+
6+
def printCat(self):
7+
print(f"{self.color} cat is {self.activity}")
8+
9+
def changeColor(self, new_color):
10+
self.color = new_color
11+
12+
13+
c1 = Cat()
14+
c2 = Cat("Black")
15+
c3 = Cat("Brown", "jumping")
16+
c4 = Cat("Red", "purring")
17+
c1.printCat()
18+
c2.printCat()
19+
c3.printCat()
20+
c4.printCat()
21+
c1.changeColor("Blue")
22+
c3.changeColor("Purple")
23+
c1.printCat()
24+
c3.printCat()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Student:
2+
def __init__(self, name="default student"):
3+
self.name = name
4+
5+
def quizcalc(self, *score):
6+
average = sum(list(score)) / 3
7+
self.message = f"Your average quiz score is {average}"
8+
9+
def printdetail(self):
10+
print(f"Hello {self.name}")
11+
print(self.message)
12+
13+
14+
s1 = Student()
15+
s1.quizcalc(10)
16+
print("--------------------------------")
17+
s1.printdetail()
18+
s2 = Student("Harry")
19+
s2.quizcalc(10, 8)
20+
print("--------------------------------")
21+
s2.printdetail()
22+
s3 = Student("Hermione")
23+
s3.quizcalc(10, 9, 10)
24+
print("--------------------------------")
25+
s3.printdetail()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Vehicle:
2+
def __init__(self):
3+
self.x_axis = 0
4+
self.y_axis = 0
5+
6+
def moveUp(self):
7+
self.y_axis += 1
8+
9+
def moveDown(self):
10+
self.y_axis -= 1
11+
12+
def moveRight(self):
13+
self.x_axis += 1
14+
15+
def moveLeft(self):
16+
self.x_axis -= 1
17+
18+
def print_position(self):
19+
print(f"({self.x_axis}, {self.y_axis})")
20+
21+
22+
car = Vehicle()
23+
car.print_position()
24+
car.moveUp()
25+
car.print_position()
26+
car.moveLeft()
27+
car.print_position()
28+
car.moveDown()
29+
car.print_position()
30+
car.moveRight()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Programmer:
2+
def __init__(self, name, language, exp):
3+
self.name = name
4+
self.language = language
5+
self.exp = exp
6+
self.flag = True
7+
8+
def addExp(self, additional_exp):
9+
self.flag = False
10+
print(f"Updating experience of {self.name}")
11+
self.exp += additional_exp
12+
13+
def printDetails(self):
14+
if self.flag:
15+
print("Horray! A new programmer is born")
16+
print(f"Name: {self.name}")
17+
print(f"Language: {self.language}")
18+
print(f"Experience: {self.exp} years")
19+
20+
21+
p1 = Programmer("Ethen Hunt", "Java", 10)
22+
p1.printDetails()
23+
print("--------------------------")
24+
p2 = Programmer("James Bond", "C++", 7)
25+
p2.printDetails()
26+
print("--------------------------")
27+
p3 = Programmer("Jon Snow", "Python", 4)
28+
p3.printDetails()
29+
p3.addExp(5)
30+
p3.printDetails()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Student:
2+
def __init__(self, name, ID, dept="CSE"):
3+
self.name = name
4+
self.ID = ID
5+
self.dept = dept
6+
7+
def dailyEffort(self, hours):
8+
self.hours = hours
9+
10+
def printDetails(self):
11+
print(f"Name: {self.name}")
12+
print(f"ID: {self.ID}")
13+
print(f"Department: {self.dept}")
14+
print(f"Daily Effort: {self.hours} hour(s)")
15+
16+
if self.hours <= 2:
17+
print("Suggestion: Should give more effort!")
18+
elif self.hours <= 4:
19+
print("Suggestion: Keep up the good work!")
20+
else:
21+
print("Suggestion: Execellent! Now motivate others.")
22+
23+
24+
harry = Student("Harry Potter", 123)
25+
harry.dailyEffort(3)
26+
harry.printDetails()
27+
print("========================")
28+
john = Student("John Wick", 456, "BBA")
29+
john.dailyEffort(2)
30+
john.printDetails()
31+
print("========================")
32+
naruto = Student("Naruto Uzumaki", 777, "Ninja")
33+
naruto.dailyEffort(6)
34+
naruto.printDetails()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Patient:
2+
def __init__(self, name, age):
3+
self.name = name
4+
self.age = age
5+
6+
def add_Symptom(self, *symptom):
7+
symptoms = ""
8+
for i in symptom:
9+
symptoms += i + ", "
10+
11+
self.symptoms = symptoms
12+
13+
def printPatientDetail(self):
14+
print(f"Name: {self.name}")
15+
print(f"Age: {self.age}")
16+
print(f"Symptoms: {self.symptoms[:-2]}")
17+
18+
19+
p1 = Patient("Thomas", 23)
20+
p1.add_Symptom("Headache")
21+
p2 = Patient("Carol", 20)
22+
p2.add_Symptom("Vomiting", "Coughing")
23+
p3 = Patient("Mike", 25)
24+
p3.add_Symptom("Fever", "Headache", "Coughing")
25+
print("=========================")
26+
p1.printPatientDetail()
27+
print("=========================")
28+
p2.printPatientDetail()
29+
print("=========================")
30+
p3.printPatientDetail()
31+
print("=========================")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Avengers:
2+
def __init__(self, name, partner):
3+
self.name = name
4+
self.partner = partner
5+
6+
def super_powers(self, *power):
7+
powers = ""
8+
for i in power:
9+
powers += i
10+
powers += ", "
11+
self.powers = powers
12+
13+
def printAvengersDetail(self):
14+
print(f"Name: {self.name}")
15+
print(f"Partner: {self.partner}")
16+
print(f"Super powers: {self.powers[:-2]}")
17+
18+
19+
a1 = Avengers("Captain America", "Bucky Barnes")
20+
a1.super_powers("Stamina", "Slowed ageing")
21+
a2 = Avengers("Doctor Strange", "Ancient One")
22+
a2.super_powers("Mastery of magic")
23+
a3 = Avengers("Iron Man", "War Machine")
24+
a3.super_powers("Genius level intellect", "Scientist ")
25+
print("=========================")
26+
a1.printAvengersDetail()
27+
print("=========================")
28+
a2.printAvengersDetail()
29+
print("=========================")
30+
a3.printAvengersDetail()
31+
print("=========================")

0 commit comments

Comments
 (0)