pleabargain

Learn Python2x The Hard Way exe35

Jun 4th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.09 KB | None | 0 0
  1. '''
  2. written for python 2.x
  3. really? ignoring the state of the art for what reason?
  4.  
  5. I would have done this with Ipython but
  6. Ipython does not handle input at all so...
  7. here it is for what it is...
  8.  
  9. the dead function keeps the if-statements from running amok
  10.  
  11. '''
  12. #what is this and why do we need it?
  13. from sys import exit
  14.  
  15. #using each decision as a function is interesting
  16. def gold_room():
  17.     print "This room is full of gold.  How much do you take?"
  18.     #this only works with python 2.x
  19.     next = raw_input("> ")
  20.     #you are not dead if you include a zero or one? that's just strange
  21.     if "0" in next or "1" in next:
  22.         how_much = int(next)
  23.     else:
  24.         dead("Man, learn to type a number.")
  25.     #throw in some kind of moralistic clap trap
  26.     if how_much < 50:
  27.         print "Nice, you're not greedy, you win!"
  28.         exit(0)
  29.     #but, you don't die. It's just a simple game.
  30.     else:
  31.         dead("You greedy bastard!")
  32.  
  33. #python 3 would require ("") around the print statements
  34. def bear_room():
  35.     print "There is a bear here."
  36.     print "The bear has a bunch of honey."
  37.     print "The fat bear is in front of another door."
  38.     print "How are you going to move the bear? Hit enter to get some options"
  39.     bear_moved = False
  40.  
  41.     while True:
  42.         next = raw_input("> ")
  43.     #added some help for the users otherwise this game would
  44.     #require the users to look at the code
  45.     print "here are your options, and you have to type them exactly: \n take honey \n taunt bear \n open door \n take a look at the code"
  46.         if next == "take honey":
  47.             dead("The bear looks at you then slaps your face off. Which means you are prabably going to restart the game.")
  48.         elif next == "taunt bear" and not bear_moved:
  49.             print "The bear has moved from the door. You can go through it now. Hit enter to see your options."
  50.             bear_moved = True
  51.         elif next == "taunt bear" and bear_moved:
  52.             dead("The bear gets pissed off and chews your leg off.")
  53.         elif next == "open door" and bear_moved:
  54.             gold_room()
  55.         else:
  56.             print "I got no idea what that means."
  57.  
  58.  
  59. def cthulhu_room():
  60.     print "Here you see the great evil Cthulhu."
  61.     print "He, it, whatever stares at you and you go insane."
  62.     print "Do you flee for your life or eat your head?"
  63.     print "Again. Not sophisticated. Type flee or head"
  64.     next = raw_input("> ")
  65.  
  66.     if "flee" in next:
  67.         start()
  68.     elif "head" in next:
  69.         dead("Well that was tasty!")
  70.     else:
  71.         cthulhu_room()
  72.  
  73. #this function is in all the if-statements...
  74. def dead(why):
  75.     print why, "Good job!"
  76.     exit(0)
  77.  
  78. def start():
  79.     print "You are in a dark room."
  80.     print "There is a door to your right and left."
  81.     print "Which one do you take?"
  82.     print "'And you have to type, left or right or the game ends. It's not very sophisticated.'"
  83.  
  84.     next = raw_input("> ")
  85.  
  86.     if next == "left":
  87.         bear_room()
  88.     elif next == "right":
  89.         cthulhu_room()
  90.     else:
  91.         dead("You stumble around the room until you starve.")
  92.  
  93.  
  94. start()
Add Comment
Please, Sign In to add comment