Skip to content

Commit 2674266

Browse files
Loops, Functions, OOPS, Inheritanc
1 parent 4e0937c commit 2674266

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PythonAutomationPractice/FirstPythonAutomaionDemo.py

+48-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,51 @@
4242
dict["FirstName"] = "P"
4343
dict["LastName"] = "D"
4444
dict[1] = 1
45-
print(dict)
45+
print(dict)
46+
47+
# if else block
48+
intamount = 3
49+
greeting = "Hello"
50+
if intamount == 3:
51+
print("condition matches")
52+
else:
53+
print("condition doesn't matches")
54+
55+
# for Loop
56+
obj = [2, 3, 4, 5, 6]
57+
58+
for i in obj:
59+
print(i * 4)
60+
61+
# Sum of first Natural numbers 1+2+3+4+5 = 15
62+
sum = 0
63+
for j in range(1, 6):
64+
sum = sum + j
65+
print(sum)
66+
67+
print("-----------------------------------")
68+
for k in range(1, 10, 2):
69+
print(k)
70+
71+
print("-----------------------------------")
72+
for m in range(10):
73+
print(m)
74+
75+
# while loop
76+
itr = 10
77+
ktr = 10
78+
while itr > 1:
79+
if itr == 3:
80+
break
81+
print(itr)
82+
itr = itr - 1
83+
84+
print("-----------------------------------")
85+
while ktr > 1:
86+
if ktr == 9:
87+
ktr = ktr - 1
88+
continue
89+
if ktr == 3:
90+
break
91+
print(ktr)
92+
ktr = ktr - 1
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# In python, function is a group related statements that perform a specific task.
2+
3+
sum = 0
4+
5+
6+
def fun(a, b):
7+
sum = a + b
8+
return sum
9+
10+
11+
c = fun(4, 3)
12+
print(c)
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from PythonAutomationPractice.OOPSDemo import Calculator
2+
3+
4+
class ChildMethod(Calculator):
5+
6+
def __init__(self):
7+
Calculator.__init__(self, self.a, self.b)
8+
9+
obj = Calculator(4,5)
10+
obj.add()

PythonAutomationPractice/OOPSDemo.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# classes are user defined bluprint or prototype
2+
# self keyword is mandatory fo calling variable names into method
3+
4+
class Calculator:
5+
sum = 0 # classes variable
6+
dif = 0
7+
8+
def __init__(self, a, b):
9+
self.a = a
10+
self.b = b
11+
12+
def add(self):
13+
sum = self.a + self.b
14+
return sum
15+
16+
def sub(self):
17+
dif = self.a - self.b
18+
return dif
19+
20+
21+
obj = Calculator(5,4)
Binary file not shown.

0 commit comments

Comments
 (0)