Skip to content

Instantly share code, notes, and snippets.

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 daffuna91/a045774e0b942faf1e142e781f0d3f24 to your computer and use it in GitHub Desktop.
Save daffuna91/a045774e0b942faf1e142e781f0d3f24 to your computer and use it in GitHub Desktop.
code-your-own-quiz: fill-in-the-blanks created by daffuna91 - https://repl.it/I4ra/1
#***------Udacity Intro to Programming: Nanodegree-----***#
#1. Prompt Question
questions = ["\nQ1. What should go in __1__? :",
"\nQ2. What should go in __2__? :",
"\nQ3. What should go in __3__? :",
"\nQ4. What should go in __4__? :"]
holders = ['__1__','__2__','__3__','__4__']
#2. Quiz Templates
quiz_text = {'easy':"\nNow let's begin the 'EASY' level quiz!\n\n>>> A common first thing to do in a language is display, 'Hello __1__!' In __2__ this is particularly easy; all you have to do is type in: __3__ 'Hello __1__!' Of course, that isn't a very useful thing to do. However, it is an example of how to output to the user using the __3__ command, and produces a program which does something, so it is useful in that capacity. It may seem a bit odd to do something in a Turing complete language that can be done even more easily with an __4__ file in a browser, but it's a step in learning __2__ syntax, and that's really its purpose.",
'medium':"\nNow let's begin the 'MEDIUM' level quiz!\n\n>>> A __1__ is created with the def keyword. You specify the inputs a\n__1__ takes by adding __2__ separated by commas between the parentheses.\n__1__s by default returns __3__ if you don't specify the value to retrun.\n__2__ can be standard data types such as string, integer, dictionary, tuple,\nand __4__ or can be more complicated such as objects and lambda functions.",
'hard':"\nNow let's begin the 'HARD' level quiz!\n\n>>> The current paragraph reads as such Artificial __1__ (A.I.) has become a 'buzz word' of publications everywhere. However to better understand A.I. we'll dive into two topics. The first is Computer __2__ (CV) which allows a computer to 'see' and label what's in the computers surroundings. The second is Natural __3__ Processing (NLP) which allows computers to understand voice commands as well as speak back to the user. All of this is now becoming possible due to Deep __4__ (DL) and Machine __4__ (ML)."}
#3. Answers to Quizes
answers = {'easy':['World','python','print','html'],'medium':['function','arguments','None','list'],'hard':['Intelligence','Vision','Language','Learning']}
choices = []
#4. Functions
def win(guesses):
#1) if Player Wins the Game
#Input: Number of tries remaining
#Output: The number of guesses game message
winning = "You won with " + str(guesses) + " guesses remaining!"
return winning
def right(choice_index,level,guesses):
#2) if Player Chooses Right
#Inputs: Which answer user is on, level, and number of tries remaining
#Outputs: Choice function with a reduced number of tries remaining
correct_answer = "\nCorrect! '" + str(choices[choice_index]) + "' is the right answer!"
print correct_answer
quiz_text[level] = quiz_text[level].replace(holders[choice_index],choices[choice_index])
return choice(level,choice_index+1,guesses)
def wrong(guesses,level,choice_index):
#3) if Player Chooses Wrong
#Inputs: Number of tries remaining, level, and which answer user is on
#Outputs: Game Over Message, or Wrong Answer Message
wrong_choice = choices.pop()
if guesses == 0:
game_over = "You've chosen wrong too many times!\nGame over!"
return game_over
else:
guesses -= 1
wrong_answer_text = "\n'" + wrong_choice + "' isn't the correct answer!\nLet's try again; you have " + str(guesses) + " trys left!"
print wrong_answer_text
return choice(level,choice_index,guesses)
def choice(level,choice_index,guesses):
#4) to Prompt User for an Answer
#Inputs: level, which question the user is on, and how many tries remain
#Outputs: Winning Message, Correct Answer Message, Wrong Answer Message, or Game Over Message
print quiz_text[level]
if choice_index == len(answers[level]):
return win(guesses)
choices.append(raw_input(questions[choice_index]))
if choices[choice_index] == answers[level][choice_index]:
return right(choice_index,level,guesses)
else:
return wrong(guesses,level,choice_index)
def start(level):
guesses_prompt = "Please select the number of guesses you'd like:"
guesses = raw_input(guesses_prompt)
if int(guesses):
guesses = int(guesses)
guess_text = "\nYou will get " + str(guesses) + " chances."
print guess_text
return choice(level.lower(),0,guesses)
def quiz():
#5) Overarching Quiz Function
user_prompt = "Please select a game difficulty by typing it in!\nPossible choices: │ easy │ medium │ hard │\nPlease type your game difficulty:"
level = raw_input(user_prompt)
intro = "\nYou've selected '" + str(level) + "'."
print intro
if level.lower() == 'hard' or level.lower() == 'medium' or level.lower() == 'easy':
return start(level)
else:
wrong_level = "\nOops! '" + level + "' is not a proper level option!\n"
print wrong_level
return quiz()
#5. Run quiz program
print quiz()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment