Skip to content

Commit f14d0ec

Browse files
committed
OOPS
1 parent 233c14b commit f14d0ec

20 files changed

+479
-3
lines changed

11_chapter/02_problem/02_problem.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def inp():
1414
re = input("Enter your guess(1,6): ")
1515
if not (re.isnumeric()):
1616
inp()
17-
elif (int(re) > 1 and int(re) <= 20):
17+
elif (int(re) >= 1 and int(re) <= 6):
1818
return int(re)
1919
else:
2020
inp()
@@ -39,7 +39,7 @@ def admin():
3939
ch = input("Admin's Choice: ")
4040
if ch.isnumeric() and ch == "1":
4141
with open("sc.txt", "w") as f:
42-
f.write(random.randint(500, 650))
42+
f.write(str(random.randint(500, 650)))
4343
elif ch.isnumeric() and ch == "2":
4444
with open("mu.txt", "w") as f:
4545
f.write("0")
@@ -50,7 +50,7 @@ def admin():
5050
def isReset():
5151
if (rd() == 1000):
5252
with open("sc.txt", 'w') as f:
53-
f.write(random.randint(500, 650))
53+
f.write(str(random.randint(500, 650)))
5454
else:
5555
return rd()
5656

12_chapter/01_problem.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
print("-----------------------")
2+
print("Welcome to Newton.Co...")
3+
print("-----------------------")
4+
5+
6+
def assign(self, i):
7+
v = ""
8+
v += "-----------------------\n"
9+
v += "Employee id " + str(i+641) + ": " + "\n"
10+
v += " Name |- " + self.name + "\n"
11+
v += " Salary |- " + str(self.salary) + "\n"
12+
v += " Language |- " + self.languages + "\n"
13+
v += " Origin |- " + self.origin + "\n"
14+
v += " Experience |- " + str(self.exp) + "\n"
15+
with open("data.txt", 'a') as f:
16+
f.write(v)
17+
18+
19+
class Emp:
20+
name = ""
21+
salary = 0
22+
exp = 0
23+
languages = ""
24+
origin = ""
25+
26+
def dataStoring(self, i):
27+
assign(self, i)
28+
29+
def dataPrinting(self, i):
30+
print("Data Stored for employee", self.name, "with emp_id ", i + 641)
31+
# our company starts with 2^6 * 10
32+
33+
34+
n = int(input("How many Employees to Add: "))
35+
employees = [Emp() for i in range(n)]
36+
37+
for i in employees:
38+
print("-----------------------")
39+
i.name = input("Enter the Name: ")
40+
i.salary = input("Enter the Salary: ")
41+
i.exp = input("Enter the years of exp: ")
42+
i.languages = input("Enter the Languages: ")
43+
i.origin = input("Enter the Origin Country: ")
44+
45+
46+
print("-----------------------")
47+
print("Storing Data Entries")
48+
49+
for emp in employees:
50+
emp.dataStoring(employees.index(emp))
51+
emp.dataPrinting(employees.index(emp))
52+
else:
53+
print("-----------------------")
54+
print("Data Has Been Stored...")
55+
print("-----------------------")

12_chapter/02_problem.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import math
2+
3+
4+
class Calculate:
5+
@staticmethod
6+
def greet(user):
7+
print(f"Hello, {user}")
8+
9+
def Square(self, n):
10+
return math.pow(n, 2)
11+
12+
def Cube(self, n):
13+
return math.pow(n, 3)
14+
15+
def sqrt(self, n):
16+
return math.pow(n, 0.5)
17+
18+
19+
j = int(input("Enter the Number: "))
20+
u = input("Your Good Name: ")
21+
n = Calculate()
22+
n.greet(u)
23+
print("Square: ", n.Square(j))
24+
print("Sqrt: ", n.sqrt(j))
25+
print("Cube: ", n.Cube(j))

12_chapter/03_problem.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A:
2+
a = 1
3+
4+
5+
object = A()
6+
object.a = 0
7+
print(object.a)

12_chapter/05_problem.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from random import randint
2+
3+
4+
class Train:
5+
6+
def __init__(self, no):
7+
self.tNo = no
8+
9+
def book(anything, fro, to):
10+
print(f"Ticket Booked for train no: {anything.tNo}") # problem 6
11+
print(f"Journey: from {fro} to {to}")
12+
13+
def getStatus(self):
14+
print(f"Train no {self.tNo} is Running on Time")
15+
16+
def getFare(self, fro, to):
17+
print(f"Fare for train no {self.tNo}:", randint(400, 2400))
18+
print(f"Journey: from {fro} to {to}")
19+
20+
21+
arr = input("Enter the Arrival station: ")
22+
dest = input("Enter the Destination station: ")
23+
24+
t = Train(12455)
25+
t.book(arr, dest)
26+
t.getFare(arr, dest)

12_chapter/Practice Set 12.png

96.9 KB
Loading

12_chapter/data.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----------------------
2+
Employee id 1:
3+
Name |- Sarthak Tulsidas Patil
4+
Salary |- 5600000
5+
Language |- Rust, kotlin, Java, C#, React
6+
Origin |- Pune, India
7+
Experience |- 6
8+
-----------------------
9+
Employee id 2:
10+
Name |- Walter White
11+
Salary |- 500000
12+
Language |- Teacher at LeHigh University
13+
Origin |- USA
14+
Experience |- 50
15+
-----------------------
16+
Employee id 641:
17+
Name |- Sarthak
18+
Salary |- 60000
19+
Language |- Rust
20+
Origin |- India
21+
Experience |- 3
22+
-----------------------
23+
Employee id 642:
24+
Name |- sarthak
25+
Salary |- 32
26+
Language |- Just chill guy
27+
Origin |- India
28+
Experience |- 3

12_chapter/oops.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class Employee:
2+
name = "Sarthak"
3+
language = "C++"
4+
salary = 1000000
5+
6+
def __init__(self, name): # is a constructor automatically runs
7+
self.name = name
8+
9+
# __ dunder methods
10+
# __ methods automatically calls
11+
12+
@staticmethod
13+
def greet():
14+
print("Welcome to Newton.Co Industries...")
15+
16+
def getInfo(self):
17+
print(f"{self.name} with {self.language} has {self.salary}/-")
18+
print(f"amount of salary with {self.experience} of experience")
19+
20+
# to hide the methods class uses abstraction and encapsulation
21+
22+
23+
def show(new):
24+
print(" ")
25+
print("--------------------------")
26+
new.greet()
27+
print("--------------------------")
28+
new.getInfo()
29+
print("--------------------------")
30+
31+
32+
new = Employee("Sarthak Tulsidas patil")
33+
new.experience = "2 years"
34+
# we can create objects
35+
new.language = "CSS, Javascript" # instance Attribute
36+
# updates to instance attribute
37+
print(new.name, new.language, new.salary, new.experience)
38+
39+
show(new)
40+
41+
# new.getInfo() = > Employee.getInfo(harry)
42+
# isiliye we use self
43+

13_chapter/01_problem.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Vec2D:
2+
def __init__(self, i, j):
3+
self.i = i
4+
self.j = j
5+
6+
def show(self):
7+
print(f"2D Vector: {self.i}i + {self.j}j = 0")
8+
9+
10+
class Vec3D(Vec2D):
11+
def __init__(self, i, j, k):
12+
super().__init__(i, j)
13+
self.k = k
14+
15+
def show(self):
16+
print(f"3D Vector: {self.i}i + {self.j}j + {self.k}k = 0")
17+
18+
19+
posVec = Vec2D(5, 7)
20+
posVec.show()
21+
hreVec = Vec3D(5, 7, 9)
22+
hreVec.show()

13_chapter/02_problem.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Animals:
2+
def __init__(self):
3+
print("Bhow Bhow")
4+
5+
6+
class Pets(Animals):
7+
def __init__(self):
8+
super().__init__()
9+
10+
11+
class Dogs(Pets):
12+
def __init__(self):
13+
super().__init__()
14+
15+
@staticmethod
16+
def bark():
17+
print("Bhow Bhow")
18+
19+
20+
d = Dogs()
21+
d.bark()

0 commit comments

Comments
 (0)