-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_baseball.py
More file actions
38 lines (33 loc) · 1.1 KB
/
Copy pathpython_baseball.py
File metadata and controls
38 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#random
import ramdom
## radom data definition
number = [0,0,0]
number[0] = random.randrange(1,9,1)
number[1] = random.randrange(1,9,1)
while (number[0] == number[1]):
number[1] = random.randrange(1,9,1)
while (number[0] == number[1] or number[1] == number[2] ):
number[2] = random.randrange(1,9,1)
num_ball = 0
num_strike = 0
num_out = 0
## rotation before 3 strike
while (num_strike < 3) :
# 3 number --> save
# insert : a, b, c data (문자열 비교 --> array 형태 저장)
input_num = input("number 3digit : ")
# check 3 number in array matche
# strike --> order , number matches
# ball --> number only matches
# out --> all unmatch
### compare 방식 --> for 문 2회 수행 (list 의 위치 숫자 비교)
for i in range(0, 3):
for j in range(0, 3):
if(num[i] == str(rn[j]) and i == j):
s_cnt += 1
elif(num[i] == str(rn[j]) and i != j):
b_cnt += 1
print("결과 : [", s_cnt, "] Strike [", b_cnt, "] Ball")
t_cnt += 1
print("---------------------------")
print(t_cnt, "번 만에 정답을 맞추셨습니다.")