Skip to content

Instantly share code, notes, and snippets.

/number_baseball.py
Created Jan 31, 2018

Embed
What would you like to do?
import random
def string_to_int(str_list):
for i, x in enumerate(str_list):
str_list[i] = int(x)
return str_list
for count in range(1, 4):
answer = []
while(1):
new = random.randint(1, 9)
if new not in answer:
answer.append(new)
if len(answer) == 3:
break
answer = [1,2,3]
print(answer)
ball = 0
strike = 0
string_input = input("숫자 세개를 띄워서 입력하세요")
string_list = string_input.split()
number_list = string_to_int(string_list)
base1 = number_list[0]
base2 = number_list[1]
base3 = number_list[2]
# print("일루: {b1} 이루 : {b2} 삼루: {b3}".format(b1=base1, b2=base2, b3=base3))
for num in number_list:
if num in answer:
ball += 1
for index, num in enumerate(number_list):
if num == answer[index]:
strike += 1
ball -= 1
print("{s} strike, {b} ball, {c} count\n".format(s=strike, b=ball, c=count))
if strike == 3:
print("축하합니다! {count}번 만에 정답을 맞추셨습니다.".format(count=count ))
print("아쉽네요! 정답은 일루: {b1} 이루 : {b2} 삼루: {b3}".format(b1=base1, b2=base2, b3=base3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.