Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. guesses_left = 10
  2. secret_word = "severin"
  3. dashes = "-" * len(secret_word)
  4. print dashes
  5. def get_guess(): # Function to ask for a guess
  6. global guess
  7. guess = input("Enter a single letter: ")
  8. if len(guess) > 1 or not guess.islower():
  9. print "Your guess needs to be a lowercase letter, and can only be one character!"
  10. while len(guess) > 1 or not guess.islower(): # Asks for new input when guess is more than 1 char or is uppercase
  11. guess = input("Enter a single letter: ")
  12. print "Your guess needs to be a lowercase letter, and can only be one character!"
  13. return guess
  14.  
  15.  
  16. def update_dashes(secret_word, dashes, guess):
  17. result = ""
  18. dashes.split()
  19. checkiftrue = False
  20. for i in range(len(secret_word)):
  21. if secret_word[i] == guess:
  22. dashes[i] == guess # Sets the dash to the letter that was correctly guessed
  23. print "That guess is correct!" + guess + " is in the word!"
  24. checkiftrue = True
  25. if checkiftrue == False:
  26. guesses_left -1
  27. print "Incorrect, guesses left: " + str(guesses_left)
  28. print guess
  29. print dashes
  30.  
  31. while guesses_left > 0 and not secret_word == dashes:
  32. get_guess()
  33. update_dashes(secret_word, dashes, guess)
  34.  
  35.  
  36. if guesses_left == 0:
  37. print "Sorry, you lose, the word was " + secret_word
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement