a fortune cookie program

Published February 21, 2018
Advertisement

So it took one day to write and bug fix.

Then another day to go through guesswork and figuring it out - to get the program to work.

I haven't got up to while loops in the book, so it took a while - a few errors before I got it working.

And I certainly haven't got as far as def methods, so using them was difficult and problematic. But I wanted my program to be complete with an exit option.

 

import random
    
def end_game():
    end_message = ("game over")
    print (end_message)
    
def game():
    againPlay = "y"
    while againPlay == "y":
        nmCookie = random.randrange(5)   
        begin = input ("cookie time, open your fortune cookie")
        if nmCookie < 1:
            print ("you are going to die someday")
            againPlay = input ("Still hungry")
        elif nmCookie == 1:
            print ("you just ate a cookie")
            againPlay = input ("Still hungry")
        elif nmCookie == 2:
            print ("you are going to eat another cookie")
            againPlay = input ("Still hungry")
        elif nmCookie == 3:
            print ("you like cookies")
            againPlay = input ("Still hungry")
        elif nmCookie == 4:
            print ("you will have a gargantuan legacy")
            againPlay = input ("Still hungry")
        else: end_game()


game ()
end_game ()
 

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement