TEXT 19
Data Science All Code Guest on 14th November 2022 11:29:24 PM
  1. Hangman:
  2. import random
  3. import os
  4.  
  5. word_list = [
  6. 'abruptly',
  7. 'absurd',
  8. 'abyss',
  9. 'affix',
  10. 'askew',
  11. ]
  12.  
  13. stages = ['''
  14.   +---+
  15.   |   |
  16.   O   |
  17.  /|\  |
  18.  / \  |
  19.       |
  20. =========
  21. ''', '''
  22.   +---+
  23.   |   |
  24.   O   |
  25.  /|\  |
  26.  /    |
  27.       |
  28. =========
  29. ''', '''
  30.   +---+
  31.   |   |
  32.   O   |
  33.  /|\  |
  34.       |
  35.       |
  36. =========
  37. ''', '''
  38.   +---+
  39.   |   |
  40.   O   |
  41.  /|   |
  42.       |
  43.       |
  44. =========''', '''
  45.   +---+
  46.   |   |
  47.   O   |
  48.   |   |
  49.       |
  50.       |
  51. =========
  52. ''', '''
  53.   +---+
  54.   |   |
  55.   O   |
  56.       |
  57.       |
  58.       |
  59. =========
  60. ''', '''
  61.   +---+
  62.   |   |
  63.       |
  64.       |
  65.       |
  66.       |
  67. =========
  68. ''']
  69.  
  70. logo = '''
  71.  _                                            
  72. | |                                            
  73. | |__   __ _ _ __   __ _ _ __ ___   __ _ _ __  
  74. | '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \
  75. | | | | (_| | | | | (_| | | | | | | (_| | | | |
  76. |_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_|
  77.                     __/ |                      
  78.                    |___/    '''
  79.  
  80. print(logo)
  81. game_is_finished = False
  82. lives = len(stages) - 1
  83.  
  84. chosen_word = random.choice(word_list)
  85. word_length = len(chosen_word)
  86.  
  87. display = []
  88. for _ in range(word_length):
  89.     display += "_"
  90.  
  91. while not game_is_finished:
  92.     guess = input("Guess a letter: ").lower()
  93.  
  94.     #Use the clear() function imported from os to clear the output between guesses.
  95.     os.system('clear')
  96.  
  97.     if guess in display:
  98.         print(f"You've already guessed {guess}")
  99.  
  100.     for position in range(word_length):
  101.         letter = chosen_word[position]
  102.         if letter == guess:
  103.             display[position] = letter
  104.     print(f"{' '.join(display)}")
  105.  
  106.     if guess not in chosen_word:
  107.         print(f"You guessed {guess}, that's not in the word. You lose a life.")
  108.         lives -= 1
  109.         if lives == 0:
  110.             game_is_finished = True
  111.             print("You lose.")
  112.    
  113.     if not "_" in display:
  114.         game_is_finished = True
  115.         print("You win.")
  116.  
  117.     print(stages[lives])
  118.  
  119. Rock Paper Scissors:
  120. import random
  121. import gameart
  122.  
  123. print("Welcome to Rock, Paper & Scissors")
  124. print(gameart.rock)
  125. print(gameart.paper)
  126. print(gameart.scissors)
  127.  
  128. print("Welcome to Rock, Paper & Scissors")
  129. print("1 - Rock")
  130. print("2 - Paper")
  131. print("3 - Scissors")
  132.  
  133.  
  134. def drawArt(choice):
  135.   if choice == 1:
  136.     print(gameart.rock)
  137.   elif choice == 2:
  138.     print(gameart.paper)
  139.   elif choice == 3:
  140.     print(gameart.scissors)
  141.  
  142.  
  143. turns = 0
  144. computerscore = 0
  145. playerscore = 0
  146. while not turns == 4:
  147.   computerchoice = random.randint(1, 3)
  148.   choice = input(
  149.     "Please enter your choice, 1 for Rock, 2 for Paper, 3 for Scissors: ")
  150.   choice = int(choice)
  151.   print("Rock, Paper, Scissors!!!!!!!!!!")
  152.   print("Computer: ")
  153.   drawArt(computerchoice)
  154.   print("Player Choice: ")
  155.   drawArt(choice)
  156.   if choice == computerchoice:
  157.     print("Tie")
  158.   elif choice == 1 and computerchoice == 2:
  159.     print("Computer Score Increment")
  160.     computerscore = computerscore + 1
  161.   elif choice == 1 and computerchoice == 3:
  162.     print("Human Score Increment")
  163.     playerscore = playerscore + 1
  164.   elif computerchoice == 1 and choice == 2:
  165.     print("Human Score Increment")
  166.     playerscore = playerscore + 1
  167.   elif computerchoice == 1 and choice == 3:
  168.     print("Computer Score Increment")
  169.     computerscore = computerscore + 1
  170.   elif computerchoice == 2 and choice == 3:
  171.     print("Human Score Increment")
  172.     playerscore = playerscore + 1
  173.   elif computerchoice == 3 and choice == 2:
  174.     print("Computer Score Increment")
  175.     computerscore = computerscore + 1
  176.   turns = turns + 1
  177.  
  178. if playerscore > computerscore:
  179.   print("Congratulations, you have won the game!")
  180. elif playerscore < computerscore:
  181.   print("You have lost the game!")
  182. elif playerscore == computerscore:
  183.   print("Game is tie!")

Coding Base is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.