Advertisement
jimMoonrock

Gallo

May 20th, 2022
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.38 KB | None | 0 0
  1. import random
  2. import string
  3.  
  4. victory_counter, loss_counter = 0, 0
  5.  
  6. print("H A N G M A N\n")
  7. while True:
  8.     list_of_words = ["python", "java",  "swift", "javascript"]
  9.     random_choices = list_of_words[random.randrange(0,4)]
  10.     user_attempts = 8
  11.     a_word_to_guess = list(random_choices)
  12.     list_with_lettrs = ["-" for _ in range(len(a_word_to_guess))]
  13.     marker, users_letter = "", ""
  14.    
  15.     menu_selection = input('Type "play" to play the game, "results" to show the scoreboard, and "exit" to quit: ')
  16.     if menu_selection == "exit":
  17.         break
  18.     elif menu_selection == "results":
  19.         print("You won: {} times.\nYou lost: {} times.".format(victory_counter,  loss_counter))
  20.         continue
  21.    
  22.    
  23.     while user_attempts > 0  and menu_selection == "play":
  24.        
  25.         print("\n{}".format("".join(list_with_lettrs)))
  26.         user_inp = input("Input a letter:   ")
  27.    
  28.    
  29.         if len(user_inp) == 1:
  30.             if user_inp not in string.ascii_lowercase:
  31.                 print("Please, enter a lowercase letter from the English alphabet.\n")
  32.                 continue
  33.             else:
  34.                 if user_inp in users_letter:
  35.                     print("You've already guessed this letter.\n")
  36.                     continue
  37.         else:
  38.             print("Please, input a single letter.\n")
  39.             continue
  40.    
  41.    
  42.         for chr in range(len(a_word_to_guess)):
  43.             if a_word_to_guess[chr] == user_inp:
  44.                 list_with_lettrs[chr] = user_inp
  45.            
  46.                 if list_with_lettrs.count(list_with_lettrs[chr]) == 1:
  47.                     marker = "Yes"
  48.                
  49.                
  50.         if user_inp not in a_word_to_guess:
  51.             print("That letter doesn't appear in the word.\n")
  52.             user_attempts -=1
  53.         else:
  54.             print()
  55.    
  56.         users_letter += user_inp
  57.    
  58.         if list_with_lettrs == a_word_to_guess:
  59.             print("You guessed the word {}!\nYou survived!".format("".join(list_with_lettrs)))
  60.             victory_counter += 1
  61.             break
  62.         elif user_attempts == 0:
  63.             if a_word_to_guess== list_with_lettrs:
  64.                 victory_counter += 1
  65.                 print("You guessed the word {}!\nYou survived!".format("".join(list_with_lettrs)))
  66.             else:
  67.                 loss_counter += 1
  68.                 print("You lost!")
  69.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement