Last active
August 7, 2017 14:23
-
-
Save yunsu3042/a8a0c6db2e1c809905f0f0178937c84e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
numbers = [] | |
strike = 0 | |
count = 0 | |
# 세개 뽑을때까지 반복 | |
while len(numbers) < 3: | |
new_number = randint(0, 9) | |
# 새로운 수 나올때까지 다시 뽑기 | |
while new_number in numbers: | |
new_number = randint(0, 9) | |
numbers.append(new_number) | |
print(numbers) | |
while(strike != 3): | |
count += 1 | |
guesses = [] | |
strike = 0 | |
ball = 0 | |
print("세 수를 하나씩 차례대로 입력하세요") | |
while(True): | |
guess1 = int(input("1번째 수를 입력하세요")) | |
if guess1 not in range(10): | |
print("범위를 벗어나는 수입니다 다시 입력해주세요") | |
else: | |
guesses.append(guess1) | |
break | |
while(True): | |
guess2 = int(input("2번째 수를 입력하세요")) | |
if guess2 not in range(10): | |
print("범위를 벗어나는 수입니다 다시 입력해주세요") | |
elif guess2 in guesses: | |
print("중복되는 수입니다. 다시 입력해주세요") | |
else: | |
guesses.append(guess2) | |
break | |
while(True): | |
guess3 = int(input("3번째 수를 입력하세요")) | |
if guess3 not in range(10): | |
print("범위를 벗어나는 수입니다 다시 입력해주세요") | |
elif guess3 in guesses: | |
print("중복되는 수입니다. 다시 입력해주세요") | |
else: | |
guesses.append(guess3) | |
break | |
i = 0 | |
while(i < 3): | |
if guesses[i] == numbers[i]: | |
strike += 1 | |
elif guesses[i] in numbers: | |
ball += 1 | |
i += 1 | |
print("{}S {}B".format(strike, ball)) | |
print("축하합니다. {}번만에 세 숫자의 값과 위치를 모두 맞추셨습니다.".format(count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment