숫자 야구 게임
[code]
import random
# 컴퓨터가 중복되지 않는 3개의 숫자를 뽑는다.
computer = []
while len(computer) < 3:
rand_num = random.randint(1, 9)
if (rand_num not in computer):
computer.append(rand_num)
#print(computer)
print("숫자야구게임을 시작합니다.")
print("1 부터 9까지 중복되지 않는 숫자 3개를 붙여서 입력하세요.")
print("-"*60)
try_count = 0
complete = False
while complete == False:
number = str(input("중복되지 않는 3개의 숫자를 입력하세요 (예:837): "))
if (len(number) != 3):
print("3개의 숫자를 입력하세요")
continue
if (number.isnumeric() == False):
print("숫자만 입력하세요")
continue
strike = 0
ball = 0
for i in range(3):
if (int(number[i]) == computer[i]):
strike += 1
elif (int(number[i]) in computer):
ball += 1
try_count += 1
print(f"{strike} Strike, {ball} Ball, Try: {try_count}")
if (strike == 3):
complete = True
print("축하합니다. 정답입니다.")
print(f"시도 횟수: {try_count}")
[/code]
댓글 1개
게시판 목록
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 91 | 4년 전 | 1161 | ||
| 90 | 5년 전 | 1293 | ||
| 89 | 5년 전 | 1855 | ||
| 88 | 5년 전 | 1894 | ||
| 87 | 5년 전 | 28249 | ||
| 86 | 5년 전 | 1423 | ||
| 85 | 5년 전 | 1288 | ||
| 84 | 5년 전 | 1306 | ||
| 83 | 5년 전 | 959 | ||
| 82 | 5년 전 | 1339 | ||
| 81 | 5년 전 | 1750 | ||
| 80 | 5년 전 | 1738 | ||
| 79 | 5년 전 | 1668 | ||
| 78 | 5년 전 | 1576 | ||
| 77 | 5년 전 | 1275 | ||
| 76 | 5년 전 | 1779 | ||
| 75 | 5년 전 | 1796 | ||
| 74 | 5년 전 | 3251 | ||
| 73 | 5년 전 | 3416 | ||
| 72 | 5년 전 | 2506 | ||
| 71 | 5년 전 | 1846 | ||
| 70 | 5년 전 | 2708 | ||
| 69 | 5년 전 | 1453 | ||
| 68 | 5년 전 | 1383 | ||
| 67 | 5년 전 | 1239 | ||
| 66 | 5년 전 | 1602 | ||
| 65 | 5년 전 | 2067 | ||
| 64 | 5년 전 | 1808 | ||
| 63 | 5년 전 | 1316 | ||
| 62 | 5년 전 | 1158 |

댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기