Skip to content

Instantly share code, notes, and snippets.

@InvisibleRasta
Created November 16, 2018 02:09
Show Gist options
  • Save InvisibleRasta/b607d98322657aae0a1fd8b6aa3f8a4b to your computer and use it in GitHub Desktop.
Save InvisibleRasta/b607d98322657aae0a1fd8b6aa3f8a4b to your computer and use it in GitHub Desktop.
Fortune Teller
# description: a game to simulate a fortune cookie
from random import randint # to generate random number
# load the fortunes
def loadFortunes():
global fortunes
fortunes[0] = "This is great, you're going to be rich and famous!"
fortunes[1] = "I'm sorry, just failure and proverty ahead for you."
fortunes[2] = "Union dues, have your wallet ready."
fortunes[3] = "It will rain later."
fortunes[4] = "You have a bright day ahead of you."
fortunes[5] = "You will not win the lotto today."
fortunes[6] = "Be sure to say \"Please and Thank You\"."
fortunes[7] = "Index funds will promise good returns."
fortunes[8] = "The expected retirement saving you have in mind, will not cover the cost of your retirment."
fortunes[9] = "Buy a lotto ticket."
# initializations
def initialization():
global fortunes, done, inputLine
fortunes = [None] * 10 # allocate array of size 10
done = False # start with done = False
loadFortunes() # call the loadFortunes method
print("Welcome to the Fortune Teller")
inputLine = input("Enter \"0\" to Exit, or anything else for a fortune.")
# print the fortune
def printFortune():
print(fortunes[randint(0, 9)])
# Main loop
def mainLoop():
global done, inputLine
if inputLine == "0":
done = True # user is done
else:
printFortune() # call function to print a funtune
inputLine = input("Another? If not press \"0") # prompt for next input
# finish
def finish():
print("Thanks for playing.")
# Main program
initialization() # call initialization method
while not done: # main loop runs under user signals done
mainLoop() # call mainloop (until done = true)
finish() # call finish (once) because we are done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment