가위바위보 게임
195
작성한 질문수 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
많이 수정했는데 일단 입력할때는 한국어로 입력하면 글꼴이 깨지니까 인덱스숫자(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
quiz 8 오류 문제
0
73
1
str() 작성 위치
0
55
1
아나콘다
0
62
1
윈도우 설치 도와주세요
0
75
1
std_weight함수에서weight만return가능한가요?
0
69
1
오른쪽위 실행버튼을 누르면 터미널에 에러가 뜨고 컨트롤+F5를 누르면 에러가 안뜹니다.
0
37
1
설치해서 시작하는데 문제가 있습니다.
0
70
1
함수 입력할 때 설명 툴팁 나오게 하려면 어떻게 하나요?
0
109
1
2장 환경설정 문의
0
77
1
스타크래프트 프로젝트
0
74
1
python 파일명.py 입력시 Python 출력
0
135
1
로드맵 질문있습니다!
0
90
2
오류
0
74
1
질문 있습니다.
0
78
1
블로그에 학습한 내용을 정리해도 괜찮을까요?
0
174
1
#퀴즈 3의 5번 질문
0
72
1
print("ㅋ"*5) 에 대한 결과가 도출되지 않습니다
0
81
1
가변인자의 위치가 중요한가요?
0
81
1
vscode옛날 버전 설치
0
223
1
글자색상이 선생님처럼 안나옵니다
0
187
1
슬프네
0
156
1
quiz 6번 관련 문의입니다.
0
131
1
퀴즈#3에 대해서 이렇게 작성해도 되나요?
0
196
1
피드백 부탁드립니다
0
93
1





