Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3b48ae7

Browse files
committed
update
1 parent 059516d commit 3b48ae7

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Example of a class for a credit card"""
2+
class CreditCard:
3+
"""Think of this function as a constructor method in java"""
4+
def __init__(self, customer, bank, account, limit):
5+
"""Create a new credit card instance"""
6+
7+
self.customer=customer
8+
self.bank= bank
9+
self.account=account
10+
self.limit= limit
11+
self.balance=0
12+
13+
def getCustomer(self):
14+
return self.customer
15+
16+
def get_bank(self):
17+
return self.bank
18+
19+
def get_account(self):
20+
return self.account
21+
22+
def get_limit(self):
23+
return self.limit
24+
25+
def get_balance(self):
26+
return self.balance
27+
28+
def charge(self, price):
29+
"""Charge given price to the card, assuming sufficient credit limit"""
30+
if price+self.balance > self.limit:
31+
return False
32+
else:
33+
self.balance+= price
34+
return True
35+
36+
def make_payment(self, amount):
37+
"""Process customer payment that reduces balance"""
38+
self.balance-=amount
39+
40+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def binarySerch(list, number, low, high) -> int:
2+
3+
#Non recursive way
4+
# low=0
5+
# high=len(list)
6+
# while low < high:
7+
# mid=int((low+high)/2)
8+
# if number > list[mid]:
9+
# low=mid
10+
# elif number == list[mid]:
11+
# return mid
12+
# else:
13+
# high=mid
14+
15+
if low >high:
16+
return 0
17+
else:
18+
mid=(low+high)//2
19+
if number == list[mid]:
20+
return mid
21+
elif number > list[mid]:
22+
return binarySerch(list, number, mid+1, high)
23+
else:
24+
return binarySerch(list, number, low, mid-1)
25+
26+
list=[2,4,7,18, 45,56,130]
27+
answer= binarySerch(list, 45, 0, len(list))
28+
print(answer)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /