-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop.py
More file actions
183 lines (162 loc) · 5.7 KB
/
oop.py
File metadata and controls
183 lines (162 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#object oriented programming
# l=[2,3,4,2,32]
# l.upper() #it encounters a error list attribute has object upper
#python is full on object
#it is made it simplicity of code
#OOP -Object,class,polymorphism,encapsulation,inheritance,abstraction
#Class is Blueprint HAr koi object class ka hota hai
a=[2]
print(type(a))
#a.append() # yeh ek function hai joh ki l ek object hai list class ka toh jab humna a. dala toh itna sara option joh aaya uska mtlb hai ki l object list class mai sai kya kya utha skta hai
# class has two data(property) or functions(behavior)
#class ka naam should be in pascal case means Thisispascalcase first letter capital
# thisiscamelcase means first letter small
# snake_case means it is like snake
#Function ek aise cheej hai joh sab jagah define hai
#method ek aise cheej hai joh class mai define hai
class Atm:
def __init__(self) : #magic methhod hai isko object call nhi karta #init is a special function or constructor
self.pin=''
self.balance=0
self.menu()
def menu(self):
user_input=input('''
Hello How could you like to proceed?
1.enter 1 your pin
2.enter 2 your deposit
3.enter 3 your withdraw
4.enter 4 your check balance
5. enter 5 to exit
''')
if user_input=='1':
self.create_pin()
elif user_input=='2':
self.deposit()
elif user_input=='3':
self.withdraw()
elif user_input=='4':
self.check_balance()
else:
print("bye")
def create_pin(self):
self.pin=input("enter your pin")
print("pin set successfull")
def deposit(self):
temp=input("entery your Pin")
if temp==self.pin:
amount=int(input("enter your amount"))
self.balance=self.balance+amount
print("Deposit Successful")
else:
print("invalid pin")
def withdraw(self):
temp=input("enter your pin")
if temp==self.pin:
amount=int(input("enter the amount"))
if amount<=self.balance:
self.balance=self.balance-amount
print("operation succesful")
else:
print("Low Balance")
else:
print("invalide pin")
def check_balance(self):
temp=input("enter your pin")
if temp==self.pin:
print(self.balance)
else:
print("invalide pin")
atm=Atm()
#CREATE NEW DATATYPE
class Fraction:
def __init__(self,n,d):
self.num = n
self.den = d
def __str__(self):#peint aayega toh yeh apna apna aaap call ho jayega
return "{}/{}".format(self.num,self.den)
def __add__(self,other):
temp_num=self.num*other.den +other.num*self.den
temp_den=self.den*other.den
return "{}/{}".format(temp_num,temp_den)
def __sub__(self,other):
temp_num=self.num*other.den -other.num*self.den
temp_den=self.den*other.den
return "{}/{}".format(temp_num,temp_den)
def __mul__(self,other):
temp_num=self.num*other.num
temp_den=self.den*other.den
return "{}/{}".format(temp_num,temp_den)
def __truediv__(self,other):
temp_num=self.num*other.den
temp_den=self.num*other.den
return "{}/{}".format(temp_num,temp_den)
b = Fraction(5,4)
c= Fraction(4,3)
print(b+c)
print(b-c)
print(b*c)
print(b/c)
#def __sub__(self,other) to subtract
#def __mul__(self,other) to multiply
#ENCLAPSULATION
# Private karne kai liya __ use karta hai
#Nothing in python is truly is private
class Atm:
def __init__(self) : #magic methhod hai isko object call nhi karta #init is a special function or constructor
self.__pin=''
self.__balance=0
self.menu()
def get_pin(self):
return self.__pin
def set_pin(self,new_pin):
self.__pin=new_pin
def menu(self):
user_input=input('''
Hello How could you like to proceed?
1.enter 1 your pin
2.enter 2 your deposit
3.enter 3 your withdraw
4.enter 4 your check balance
5. enter 5 to exit
''')
if user_input=='1':
self.create_pin()
elif user_input=='2':
self.deposit()
elif user_input=='3':
self.withdraw()
elif user_input=='4':
self.check_balance()
else:
print("bye")
def create_pin(self):
self.__pin=input("enter your pin")
print("pin set successfull")
def deposit(self):
temp=input("entery your Pin")
if temp==self.__pin:
amount=int(input("enter your amount"))
self.__balance=self.__balance+amount
print("Deposit Successful")
else:
print("invalid pin")
def withdraw(self):
temp=input("enter your pin")
if temp==self.__pin:
amount=int(input("enter the amount"))
if amount<=self.__balance:
self.__balance=self.__balance-amount
print("operation succesful")
else:
print("Low Balance")
else:
print("invalide pin")
def check_balance(self):
temp=input("enter your pin")
if temp==self.__pin:
print(self.__balance)
else:
print("invalide pin")
atm=Atm()
y=atm.get_pin()
print(y)