-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
47 lines (36 loc) · 1.29 KB
/
run.py
File metadata and controls
47 lines (36 loc) · 1.29 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
from flask import Flask
from flask import request
from twilio import twiml
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def incoming_call():
"""Handle incoming call and give instructions"""
response = twiml.Response()
response.say("Welcome to the Fizz Buzz hotline.", voice='woman')
with response.gather(action="/play_game", method="POST") as g:
g.say("Please enter a number and press pound to continue.", voice='woman')
response.redirect('/')
return str(response)
@app.route("/play_game", methods=['GET', 'POST'])
def play_game():
"""Handle key press from player and respond"""
response = twiml.Response()
if 'Digits' in request.values:
number = int(request.values['Digits'].strip('#'))
fizz_buzz = get_response(number)
response.say(fizz_buzz, voice='woman')
return str(response)
def get_response(entered_number):
fizzy_response = ""
for n in range(1, entered_number+1):
if n % 3 == 0 and n % 5 == 0:
fizzy_response += "Fizz Buzz "
elif n % 3 == 0:
fizzy_response += "Fizz "
elif n % 5 == 0:
fizzy_response += "Buzz "
else:
fizzy_response += "{} ".format(n)
return fizzy_response
if __name__ == "__main__":
app.run(debug=True)