Skip to content

Instantly share code, notes, and snippets.

@fer408
Created February 1, 2016 08:16
Show Gist options
  • Save fer408/46533df4ab6a3cf08bea to your computer and use it in GitHub Desktop.
Save fer408/46533df4ab6a3cf08bea to your computer and use it in GitHub Desktop.
Intro to programming Project 2
# this greets the user
print "Welcome to my reverse madLibs generator, My name is Fernando, I hope you enjoy the game."
#this is to ask the user which difficulty he/she would like to use.
print "What difficulty would you like to choose?"
print "Press 1 for easy, 2 for medium or 3 for hard"
# possible strings
string1 = "I'd rather _1_ on my _2_ than _3_ on my _4_ "
answer1 = ["die","feet","live","knees"]
string2 = "They _1_ to bury _2_,they did _3_ know _4_ were seeds"
answer2 = ["tried","us","not","we"]
string3 = "With _1_ _2_ comes _3_ _4_"
answer3 = ["great","power","great","responsability"]
blank = ["_1_","_2_","_3_","_4_"]
# difficulty_selector options.
easy = 1
medium = 2
hard = 3
# this is the function that selects the levels.
def difficulty_selector():
user_input = raw_input()
if user_input == '1':
print "easy it is"
return string1,answer1
if user_input == '2':
print "medium it is"
return string2,answer2
else:
print "hard it is"
return string3,answer3
# code that replaces the blank variables to the correct string if user inputs
# the correct string otherwise user is told to try again.
def play_game():
string, answerlist = difficulty_selector()
print string
i = 0
while i < 4:
answer = raw_input("What is the correct answer to?"+blank[i])
if answer == answerlist[i]:
print "Good job"
string = string.replace(blank[i],answerlist[i])
print string
i += 1
else:
print "Wrong bro,try again"
#calling this makes everything possible.
play_game()
print "Thanks for playing,have a good day"
# Special thanks to everyone that helped me on this project,
# Udacity Coaches James for his excellent review,
# fellow Udacians who contributed to me finally finishing this project. Thanks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment