Skip to content

Instantly share code, notes, and snippets.

@ArkinDharawat
Last active June 4, 2017 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArkinDharawat/6095f514a1b86f4cde191e4a84f93f33 to your computer and use it in GitHub Desktop.
Save ArkinDharawat/6095f514a1b86f4cde191e4a84f93f33 to your computer and use it in GitHub Desktop.
Alexa Armstrong Skill
from flask import Flask, render_template
from flask_ask import Ask, statement, question, session
import random
app = Flask(__name__)
ask = Ask(app, "/")
def armstrong(num):
order = len(str(num))
num_sum = 0
temp = num
while temp > 0:
digit = temp % 10
num_sum += digit ** order
temp //= 10
if num == num_sum:
return True
else:
return False
@ask.launch
def new_game():
welcome_msg = render_template('welcome')
return statement(welcome_msg)
@ask.intent("AnswerIntent", convert = {'first': int} )
def answer(first):
if armstrong(int(first)):
msg = render_template('win')
else:
msg = render_template('lose')
return statement(msg)
if __name__ == '__main__':
app.run()
welcome: Hello. Welcome to the IsArmstrong skill. Give me a number and I will tell you if it's an Armstrong number.
win: Yes, This number is an Armstrong number!
lose: Sorry, this is not an Armstrong number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment