Home > Blockchain >  Python - print() is not giving any output of the list that contains ASCII arts
Python - print() is not giving any output of the list that contains ASCII arts

Time:05-03

So I am working on a Paper Rock and Scissor Game, pretty easy it may seem but I've encountered a problem with printing ASCII arts of paper, rock, and scissors, which I incorporated into the list. The code looks like this:

import random
rock = '''
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
'''

paper = '''
    _______
---'   ____)____
          ______)
          _______)
         _______)
---.__________)
'''

scissors = '''
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
'''

rps_list = rock paper scissors
player = int(input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors.: "))
computer = random.randint(0,2)
print(rps_list[player])
print(rps_list[copmuter])

After that, I have some if functions to determine the outcome of the game but what bothers me is that I can't get the output to work when I am using the print function and list with ASCII arts inside the list and I don't get why. If I were to use just e.g.

print(rock)
print(scissors)
print(paper)

I get the beautiful arts printed but not with the way I am doing it. What am I doing wrong?

CodePudding user response:

rock paper scissors is string concatenation.

Use rps_list = [rock, paper, scissors]

CodePudding user response:

You need to set rps_list as a list as follows

rps_list = [rock, paper, scissors]

CodePudding user response:

This is because rock, paper, and scissors are strings and you try to add all of them.

In python 'Hello' 'hi' = 'hellohi'. This is called String Concatenation.

import random
rock = '''
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
'''

paper = '''
    _______
---'   ____)____
          ______)
          _______)
         _______)
---.__________)
'''

scissors = '''
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
'''

rps_list = [rock,paper,scissors]
player = int(input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors.: "))
computer = random.randint(0,2)
print(rps_list[player])
print(rps_list[computer])

There is another way you could change rock, paper, and scissors to a list and then add them.

import random
rock = ['''
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
''']

paper = ['''
    _______
---'   ____)____
          ______)
          _______)
         _______)
---.__________)
''']

scissors = ['''
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
''']

rps_list = rock paper scissors
player = int(input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors.: "))
computer = random.randint(0,2)
print(rps_list[player])
print(rps_list[computer])
  • Related