Python 100개의 프로젝트

4일차 - 초급 - 무작위화 및 파이썬 리스트

성공할준 2024. 11. 27. 11:47

오늘은 가위바위보 게임을 만들어봤다

 

난 몰랐는데 세계 가위바위보 협회라는게 실제로 존재한다고 한다ㅋㅋㅋ

 

강사는 f스트링을 사용했던데, 파이썬은 f스트링을 얼마나 잘 쓰느냐도 중요한 것 같다.

 

난 살짝 코드 그대로를 길게 늘어뜨려놨는데, 나중에 최적화하는 방법도 공부해봐야겠다

 

그래도 스스로 구현했다는 것에 뿌듯함을 느꼈다..'ㅅ'

 

import random

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

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

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


your_choice = input("안녕하세요 가위바위보 게임에 오신 것을 환영합니다. 어떤걸 내시겠어요?\n 가위 : 0 바위 : 1 보 : 2\n")


computer_choice = random.randint(0,2)

# 가위(0)는 보(2)를 이긴다
# 바위(1)는 가위(0)를 이긴다
# 보(2)는 바위(1)를 이긴다


if your_choice == '0' :
    print(scissors)
    if computer_choice == 0 :
        print(scissors)
        print("비겼어요")
    elif computer_choice == 1:
        print(rock)
        print("졌어요")
    else:
        print(paper)
        print("이겼어요")

elif your_choice == '1' :
    print(rock)
    if computer_choice == 0:
        print(scissors)
        print("이겼어요")
    elif computer_choice == 1:
        print(rock)
        print("비겼어요")
    else:
        print(paper)
        print("졌어요")

elif your_choice == '2' :
    print(paper)
    if computer_choice == 0:
        print(scissors)
        print("졌어요")
    elif computer_choice == 1:
        print(rock)
        print("이겼어요")
    else:
        print(paper)
        print("비겼어요")

심심할때면 컴퓨터와 가위바위보를 해보자