Amazon Alexa Skills Development Tutorial
In this video, we share how we made a quiz skill that has a database integration so that your progress can be saved.
These are the components of an Alexa skill:
- Interaction model (acts like a front-end interface)
- Logic (Code is written in programming languages like python, JS, Java) usually hosted in AWS Lambda
You will need 2 accounts to accomplish this:
- AWS account for AWS Lambda and DynamoDB (aws.amazon.com)
- Amazon developer account for the skill builder (interaction model etc) and certification. (developer.amazon.com)
import random # we need this package to shuffle the answers
questions= [“what’s the game’s author’s name?”, “what’s 2+2”, “what’s the capital of the United States?”,
“What’s the capital of China? “, “what’s the capital of India?”]
answers= [[“John”,”Jack”,”Jim”],[4,5,6],[“Washington DC”, “Seattle”, “New York”] ,[“Beijing”, “Shanghai”, “Tibet”],[“New Delhi”, “Mumbai”, “Banglore”]]
choiceLetter=[‘A’,’B’,’C’]
def quiz():
print( “Welcome to the game! You will get five questions. Type the choice letter(A, B, C) to enter the right answer”)
index=0 # keeping track of the index
score=0 # keeping track of the quiz score
for i in range(len(questions)):
print questions[index] # print question
answerIndex=0
shuffleAns= list(answers[index]) # copy the answer list to a different variable
random.shuffle(shuffleAns) #shuffle the answers
for answer in shuffleAns:
print (“({}) {}”.format(choiceLetter[answerIndex],answer))
if answer==answers[index][0]: # making sure that the correct asswer’s idndex after shuffling is saved
afterShuffle= choiceLetter[answerIndex]
answerIndex+=1
a= raw_input(“Enter your choice(A/B/C): “)
if a == afterShuffle:
print “Correct!”
score+=1
else:
print “wrong answer!”
index+=1
print “”
print (“\nYour score is {} out of {} \n”.format(score,len(questions)))
# This will run the quiz
quiz()
Want more information on how to become Amazon AWS Certified? Learn more!