-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneBook.py
More file actions
37 lines (30 loc) · 937 Bytes
/
Copy pathPhoneBook.py
File metadata and controls
37 lines (30 loc) · 937 Bytes
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
def hashingAlgo(number):
digits = number[-2:]
key = int(int(digits)/ 10)
return key
class book():
def __init__(self):
self.__Name = "No name"
self.__num = ""
def getName(self):
return self.__Name
def getNum(self):
return self.__num
PhoneBook = [[book() for i in range(2)] for j in range(10)]
for i in range(3):
Name = input("Enter a name: ")
num = input("Enter a phone number: ")
hashkey = hashingAlgo(num)
added = False
while added == False:
if hashkey > 9:
hashkey = 0
else:
if PhoneBook[hashkey][0] != "No name":
PhoneBook[hashkey][0] = Name
PhoneBook[hashkey][1] = num
added = True
else:
hashkey += 1
for a in range(10):
print(PhoneBook[a][0]," ", PhoneBook[a][1])