Guest User

Untitled

a guest
Jun 22nd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.81 KB | None | 0 0
  1. from random import choice
  2. word_list=["alien", "sponge", "bar", "night", "valkyrie", "water", "gentle", "python", "boring", "hand", "cereal", "word", "sad", "minecraft", "lamb", "turkey", "fire", "whelp", "dwarves", "cyan", "skyrim", "pie", "cake", "portal", "life", "death", "ogre", "mister"]
  3. selected_word=choice(word_list)
  4. characters=len(selected_word)
  5. length=characters
  6. num=characters-1
  7. word=list(selected_word)
  8. guessed_word_string="-"*characters
  9. guessed_word=list(guessed_word_string)
  10. print "Note that this is only a test, and therefore, there are only a few words in the game."
  11. win=False
  12. lose=False
  13. tries=input("How many tries do you want? (Standard is 10, maximum is 50) Please remember to use numbers instead of words, for the latter will crash the game: ")
  14. if tries>50:
  15.     while tries>50:
  16.         print "Oops, you did something wrong. Please do not excede the maximum number of tries in your selection."
  17.         tries=input("Go ahead, try again: ")
  18. print "The word is", characters, "letters long."
  19. print "You have", tries, "tries left."
  20. game="running"
  21. while game=="running":
  22.     if win==True:
  23.         print "Congratulations! you guessed the word!"
  24.         game="finished"
  25.     elif lose==True:
  26.         print "Oh, bummer... You lose. :( Maybe you want to try again?"
  27.         game="finished"
  28.     else:
  29.         while win==lose:
  30.             if word==guessed_word:
  31.                 win=True
  32.             elif tries==0:
  33.                 lose=True
  34.             else:
  35.                 if win==True:
  36.                     print "Congratulations! you guessed the word!"
  37.                 elif lose==True:
  38.                     print "Oh, bummer... You lose. :( Maybe you want to try again?"
  39.                 else:
  40.                     print guessed_word_string
  41.                     answer=raw_input("Choose a letter to guess: ")
  42.                     while len(answer)!=1:
  43.                         answer=raw_input("You must select a single letter: ")
  44.                     if answer in word:
  45.                         while answer!=word[num]:
  46.                             num-=1
  47.                         if guessed_word[num]==answer:
  48.                             print "Silly! You already selected that letter!"
  49.                         else:
  50.                             guessed_word[num]=answer
  51.                             num=characters-1
  52.                             guessed_word_string=""
  53.                             while length>0:
  54.                                 length-=1
  55.                                 guessed_word_string=guessed_word[length]+guessed_word_string
  56.                             length=characters
  57.                             print "Correct!"          
  58.                     else:
  59.                         print "Nope, try again!"
  60.                         tries-=1
  61.                         print "You have", tries, "tries left."
Add Comment
Please, Sign In to add comment