Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import random
- contin = 0
- while contin != "q":
- Animals = ["jaguar", "cat", "dog", "cheetah", "horse", "monkey", "donkey", "rabbit", "chicken", "rooster", "zebra", "cow"]
- Lenths = [6, 3, 3, 7, 5, 6, 6, 6, 7, 7, 5, 3]
- Word = Animals[(random.randint(0, len(Animals)-1))]
- Answer = list(Word)
- TriesLeft = int(round(len(Answer)*1.5))
- Revealed = []
- Guessed = []
- i = 0
- Solve = 0
- while i < len(Answer):
- Revealed.append("___")
- i+=1
- print "%s %s letters total. You have %s tries" % (Revealed, len(Answer), TriesLeft)
- while TriesLeft > 0 and Solve == 0:
- Guess = list(raw_input("\nPlease guess a letter: "))
- Guess1 = [0,0]
- Invalid = 0
- while Guess1 != [1,1] or Invalid == 1:
- while len(Guess) != 1 or not str.isalpha(Guess[0]):
- Guess = list(raw_input("\nError Detected - Please guess a letter: "))
- Guess1.pop(0)
- Guess1.insert(0,1)
- try:
- while Guess[0] in Guessed:
- print
- except:
- Invalid = 1
- if Invalid == 0:
- while Guess in Guessed:
- Guess = list(raw_input("\nYou have already guessed this letter: "))
- Guess1.pop(0)
- Guess1.insert(0,0)
- Guess1.pop(1)
- Guess1.insert(1,1)
- try:
- Guess[0] = str.lower(Guess[0])
- except:
- Guess1 = [0,0]
- if Guess not in Guessed:
- Guessed.append(Guess)
- if Guess not in Answer and Guess not in Guessed:
- print "Sorry, %s is not in the word. You have %s tries left." % (Guess[0], TriesLeft)
- TriesLeft -= 1
- for index, item in enumerate(Revealed):
- if index == 0:
- print "(%s," % item,
- elif index == (len(Revealed)-1):
- print "%s)" % item,
- else:
- print "%s," % item,
- if "___" not in Revealed:
- Solve = 1
- print "Congratulations, you have found the word!\n"
- contin = raw_input("Press q to quit or any other key to continue")
- if TriesLeft == 0:
- Solve = 1
- print "Sorry, you have failed. The word was %s" % Word
- contin = raw_input("Press q to quit or any other key to continue")
- if Solve != 1:
- if Guess[0] in Answer:
- yes = 0
- for index, item in enumerate(Answer):
- if item == Guess[0]:
- Revealed.pop(index)
- Revealed.insert(index, Guess[0])
- yes = 1
- if yes == 1:
- print "The letter was found: "
- print " - The following letters are unavailable: ",
- for item in Guessed:
- print item,
Add Comment
Please, Sign In to add comment