Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    6
  • comments
    2
  • views
    625

a fortune cookie program

Sign in to follow this  
WinterDragon

367 views

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 ()
 

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!