• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

가위바위보 게임

21.03.10 00:45 작성 조회수 108

1

import random
computer = ["가위", "바위", ""]

my_count = 0
computer_count = 0

while True:
my_hand = input("무엇을 낼까요?:")
computer_hand = input((random.choice(computer)))
if my_hand == "바위" and computer_hand == 0:
print("비겼습니다!")
print(my_count, ":", computer_count )
elif my_hand == "가위" and computer_hand == 1 :
print("비겼습니다!")
print(my_count, ":", computer_count )
elif my_hand == "" and computer_hand == 2:
print("비겼습니다!")
print(my_count, ":", computer_count )



아직 미완성 식이긴 합니다만... 왜 비겼을 때 print가 나오지 않을까요..

답변 2

·

답변을 작성해보세요.

0

haon님의 프로필

haon

2021.03.10

완성할때까지 안되면 다시 질문해주세요.

0

haon님의 프로필

haon

2021.03.10

많이 수정했는데 일단 입력할때는 한국어로 입력하면 글꼴이 깨지니까 인덱스숫자(0, 1, 2)로 바꿨습니다.

숫자로 입력하면 어떤순서로 "가위", "바위", "보"인지 알 수 없으니까 while시작하기전에 computer리스트를 한번 출력했습니다. 정수(숫자)로 입력할때는 정수형int(input())로 입력받아야해서 바꿨습니다.

가장 문제가 많은곳은 9줄입니다. 9줄에서 왜 computer_hand = input((random.choice(computer))) 라고 적었나요?

1:일단 괄호의수가 안맞아요. 

2:왜 컴퓨터인데 input로 입력받아야 하나요? 컴퓨터는 자동(랜덤)으로 선택못하나요?

3:input로는 무었을 입력받고싶나요? 문자열? 아니면 숫자?

4:random.choice(computer)는 필요하나요?

5:설명보다 먼저 코드가 제대로 작동돼야합니다. 자기가 만든가위바위보게임의 규칙은 자기는 알고있습니다.

6:random.choice(computer)를 보여주고 싶으면 따로따로  print(random.choice(computer))다음줄에 computer_hand = int(input()) 로 해야합니다.

다음은 if문인데 여기는 자기가 확인하세요. my_hand의바위 가위 보와 computer_hand의 0, 1, 2가 안맞을것같아요.computer_hand를 정수(0, 1, 2)와 비교하고 싶다면 computer_hand = int(input())로 해야합니다.

그리고 기능을 추가했는데 break입니다. 정상적으로 실행되고 끝나는지 확인하기위해서입니다.

그래서 몄번이나 놀고싶으면 빼도됩니다.

                                                                                                                                                        

import random

computer = ["가위", "바위", "보"]

my_count = 0

computer_count = 0

print(computer)

while True:

my_hand = int(input("무엇을 낼까요?:"))

computer_index = random.randint(0, 2)

computer_hand = computer[computer_index]

print(computer_hand)

if my_hand == computer_index:

print("비겼습니다!")

print(my_count, ":", computer_count )

break

elif my_hand == computer_index:

print("비겼습니다!")

print(my_count, ":", computer_count )

break

elif my_hand == computer_index:

print("비겼습니다!")

print(my_count, ":", computer_count )

break