- Hangman:
- import random
- import os
- word_list = [
- 'abruptly',
- 'absurd',
- 'abyss',
- 'affix',
- 'askew',
- ]
- stages = ['''
- +---+
- | |
- O |
- /|\ |
- / \ |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- /|\ |
- / |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- /|\ |
- |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- /| |
- |
- |
- =========''', '''
- +---+
- | |
- O |
- | |
- |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- |
- |
- |
- =========
- ''', '''
- +---+
- | |
- |
- |
- |
- |
- =========
- ''']
- logo = '''
- _
- | |
- | |__ __ _ _ __ __ _ _ __ ___ __ _ _ __
- | '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \
- | | | | (_| | | | | (_| | | | | | | (_| | | | |
- |_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_|
- __/ |
- |___/ '''
- print(logo)
- game_is_finished = False
- lives = len(stages) - 1
- chosen_word = random.choice(word_list)
- word_length = len(chosen_word)
- display = []
- for _ in range(word_length):
- display += "_"
- while not game_is_finished:
- guess = input("Guess a letter: ").lower()
- #Use the clear() function imported from os to clear the output between guesses.
- os.system('clear')
- if guess in display:
- print(f"You've already guessed {guess}")
- for position in range(word_length):
- letter = chosen_word[position]
- if letter == guess:
- display[position] = letter
- print(f"{' '.join(display)}")
- if guess not in chosen_word:
- print(f"You guessed {guess}, that's not in the word. You lose a life.")
- lives -= 1
- if lives == 0:
- game_is_finished = True
- print("You lose.")
- if not "_" in display:
- game_is_finished = True
- print("You win.")
- print(stages[lives])
- Rock Paper Scissors:
- import random
- import gameart
- print("Welcome to Rock, Paper & Scissors")
- print(gameart.rock)
- print(gameart.paper)
- print(gameart.scissors)
- print("Welcome to Rock, Paper & Scissors")
- print("1 - Rock")
- print("2 - Paper")
- print("3 - Scissors")
- def drawArt(choice):
- if choice == 1:
- print(gameart.rock)
- elif choice == 2:
- print(gameart.paper)
- elif choice == 3:
- print(gameart.scissors)
- turns = 0
- computerscore = 0
- playerscore = 0
- while not turns == 4:
- computerchoice = random.randint(1, 3)
- choice = input(
- "Please enter your choice, 1 for Rock, 2 for Paper, 3 for Scissors: ")
- choice = int(choice)
- print("Rock, Paper, Scissors!!!!!!!!!!")
- print("Computer: ")
- drawArt(computerchoice)
- print("Player Choice: ")
- drawArt(choice)
- if choice == computerchoice:
- print("Tie")
- elif choice == 1 and computerchoice == 2:
- print("Computer Score Increment")
- computerscore = computerscore + 1
- elif choice == 1 and computerchoice == 3:
- print("Human Score Increment")
- playerscore = playerscore + 1
- elif computerchoice == 1 and choice == 2:
- print("Human Score Increment")
- playerscore = playerscore + 1
- elif computerchoice == 1 and choice == 3:
- print("Computer Score Increment")
- computerscore = computerscore + 1
- elif computerchoice == 2 and choice == 3:
- print("Human Score Increment")
- playerscore = playerscore + 1
- elif computerchoice == 3 and choice == 2:
- print("Computer Score Increment")
- computerscore = computerscore + 1
- turns = turns + 1
- if playerscore > computerscore:
- print("Congratulations, you have won the game!")
- elif playerscore < computerscore:
- print("You have lost the game!")
- elif playerscore == computerscore:
- print("Game is tie!")
Recent Pastes