언어/파이썬

[부트캠프] random 함수와 배열 활용

앨리스.W 2023. 5. 1. 12:54

👇코드

#ascii art에서 참고
rock = '''
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
'''

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

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

#Write your code below this line 
import random

#먼저 위의 코드들을 배열에 넣는다
img = [rock, paper, scissors]

MyTrun = int(input("type 0 for rock, 1 for paper, 2 for scissors\n"))
if MyTrun >= 3:
  print("wrong number")
else:
  print(img[MyTrun])
  ComTurn = random.randint(0,2)
  print("Computer chose:")
  print(img[ComTurn])
  #승리는 결정은 elif문으로
  
  if MyTrun == 0 and ComTurn == 2:
    print("you win")
  elif MyTrun == 2 and ComTurn == 0:
    print("you lose")
  elif MyTrun > ComTurn:
    print("you win")
  elif MyTrun < ComTurn:
    print("you lose")
  elif MyTrun == ComTurn:
    print("draw")

 

✍ 파이썬은 if문 쓸때 들여쓰기가 중요하다!

반응형