1

I try to print some simple ascII art but none of of it shows up, what am I doing wrong? I would think this would work because the person has to input something to continue in the first place. All I am trying to do is make a simple game of rock, paper scissors. Also i am on python 3.9.4 if that has anything to do with it.

import random
import time
import ctypes
import os


def Main_Game():
    y = input("Enter choice: ")
    b = random.choice(choices)
    # both put same; draw
    if y == b:
        print("Game ended with a draw!")
        print("Player chose = " + y + "| Bot chose = " + b)
    # player puts rock and bot puts paper; bot wins
    elif y == "rock" and b == "paper":
        print("Bot won the match with paper!")
        print("Player chose = " + y + "| Bot chose = " + b)
    # player puts paper and bot puts rock; player wins
    elif y == "paper" and b == "rock":
        print("Player won the match with paper!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
    # player puts paper and bot puts scissors; bot wins
    elif y == "paper" and b == "scissors":
        print("Bot won the match with scissors!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
    # player puts scissors and bot puts paper; player wins
    elif y == "scissors" and b == "paper":
        print("Player won the match with scissors!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
    # player puts rock and bot puts scissors; player wins
    elif y == "rock" and b == "scissors":
        print("Player won the match with rock!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
    # player puts scissors and bot puts rock; bot wins
    elif y == "scissors" and b == "rock":
        print("Bot won the match with rock!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
    elif y == 'rock':
        print("""
            _______
        ---'   ____)
              (_____)
              (_____)
              (____)
        ---.__(___)
        """)
        print("""
              #     #   #####  
              #     #  #     # 
              #     #  #       
              #     #   #####  
              #   #         # 
              # #    #     # 
              #      #####  
        """)
    elif y == 'paper':
        print("""
             _______
        ---'    ____)____
                   ______)
                  _______)
                 _______)
        ---.__________)
        """)
        print("""
              #     #   #####  
              #     #  #     # 
              #     #  #       
              #     #   #####  
              #   #         # 
              # #    #     # 
              #      #####  
        """)
    elif y == 'scissors':
        print("""
            _______
        ---'   ____)____
                  ______)
               __________)
              (____)
        ---.__(___)
        """)
        print("""
              #     #   #####  
              #     #  #     # 
              #     #  #       
              #     #   #####  
              #   #         # 
              # #    #     # 
              #      #####  
        """)
    time.sleep(3)
    clear()
    Main_Game()


clear = lambda: os.system("cls")
choices = ["rock", "paper", "scissors"]
ctypes.windll.kernel32.SetConsoleTitleW("Playing rock, paper, scissors!")
Main_Game()
1
  • 2
    Probably because y has a \n appended to the end of it, so it doesn't match any of your choices. Try print(repr(y)) to see what's really there. Commented Apr 25, 2021 at 3:10

4 Answers 4

6

elif only checks its condition if the previous branches were all false, and your branches handle every possible input. You probably meant for the elif y == 'rock' line to be if y == 'rock', so we check the condition no matter the values of the previous conditions.

Sign up to request clarification or add additional context in comments.

Comments

3

Silvio's answer solves your immediate problem, but I thought I'd post some suggestions on how to clean up this code a bit.

First off, the ascii art data makes the logic a bit hard to read, I would move these to some const values at the start of the script:

ROCK_ART = """
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
"""
PAPER_ART = """
    _______
---'    ____)____
           ______)
          _______)
         _______)
---.__________)
"""
SCISSORS_ART = """
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
"""
VS_ART = """
#     #   #####  
#     #  #     # 
#     #  #       
#     #   #####  
#   #         # 
# #    #     # 
#      #####  
"""

You can define a dictionary for easy lookup of these images.

ART = {
    "rock": ROCK_ART,
    "paper": PAPER_ART,
    "scissors": SCISSORS_ART,
    "vs": VS_ART,
}

Now there's a lot of repeated logic in checking who wins. Imagine if you wanted to program to play "Rock paper scissors lizard spock". Thats a whole lot of choices to check and values to hard code. What if instead we put these rules into a dictionary.

MATCH_UPS = {
    "rock": "scissors",
    "paper": "rock",
    "scissors": "paper",
}

To see who wins a fight you could do if MATCH_UPS[y] == b to see if the user wins. On that note, use more descriptive names for variables or things will get confusing for you fast.

Putting this altogether:

def main_game():
    user_choice = input("Enter choice: ")
    bot_choice = random.choice(list(MATCH_UPS.keys()))

    print(ART[user_choice])
    print(ART["vs"])
    print(ART[bot_choice])
    print(f"Player chose = {user_choice} | Bot chose = {bot_choice}")

    if user_choice == bot_choice:
        print("Game ended with a draw!")
    elif MATCH_UPS[user_choice] == bot_choice:
        print(f"Player won the match with {user_choice}!")
    else:
        print(f"Bot won the match with {bot_choice}!")

    time.sleep(3)
    os.system("cls")
    main_game()


if __name__ == "__main__":
    main_game()

1 Comment

Man thanks I will be sure to do this for future projects.
1

You should try to draw the flow diagram of your game. In your code when a player enters a choice, you generate a random choice from the bot and compare it using if and elif, but when a statement matches let's say elif y == 'rock' and b == 'scissors': then the flow would stop as the code only goes through elif statements if the previous ones didn't match so you should change your code by breaking this part

  elif y == "scissors" and b == "rock":
        print("Bot won the match with rock!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
  if y == 'rock':

so that it executes the ASCII print statements as well

Comments

1

It is not

elif y=='rock':

change it to

if y=='rock':

because you want to print the ascii art for the players input, and it does not depend on the system's choice.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.