Last active
June 4, 2017 14:00
-
-
Save ArkinDharawat/6095f514a1b86f4cde191e4a84f93f33 to your computer and use it in GitHub Desktop.
Alexa Armstrong Skill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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