-
Notifications
You must be signed in to change notification settings - Fork 0
/
phone_number.py
57 lines (45 loc) · 1.61 KB
/
phone_number.py
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
#!/usr/bin/env python2.7
import random
from data_structures import queue
"""
Silly command line thing that will randomly generate phone numbers that the
user must confirm if correct or not. This implementation uses a queue to append
a random number and basically shift the numbers over by one. For example:
Original number:
1234567890
Is this your number? no
2345678905
etc, etc
The idea came from reading about people working on building the dumbest way to
enter your phone number on a website (you can see it here:
http://www.dailydot.com/lol/stupid-phone-number-entry-field-challenge/)
"""
VALID_RESPONSES = ('y', 'n')
class PhoneNumber(object):
def __init__(self):
self.number = queue.IterableQueue()
def generate(self):
"""
Generate the random number. If it is the first time, generate 10 random
integers for the starting phone number.
"""
if self.number.size() == 0:
for i in xrange(0, 10):
num = random.randint(0, 9)
self.number.enqueue(num)
self.number.dequeue()
rand_num = random.randint(0, 9)
self.number.enqueue(rand_num)
return ''.join([str(i) for i in self.number])
if __name__ == '__main__':
base_number = PhoneNumber()
answer = "n"
while answer == "n":
number = base_number.generate()
print "is your number {}? y or n".format(number)
answer = raw_input()
if answer == 'y':
print "WAHOO! "
else:
print "that is not a valid response. valid responses are " \
"{}".format(', '.join((VALID_RESPONSES)))