-
Notifications
You must be signed in to change notification settings - Fork 10
[숫자 야구 게임] 정영인 미션 제출합니다 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
67bc20c
588494e
afc6754
97d9fc4
e59b512
7fd8bae
76f6f9d
f030d6b
dc75a7c
5413a34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,80 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def main(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import random | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def check_valid_input(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arr_list=list(input("숫자를 입력하세요: ")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if len(arr_list)!=3: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError("3 자리 숫자를 입력하세요") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in range(3): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not arr_list[i].isdigit(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError("정수를 입력하세요") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if len(arr_list) != len(set(arr_list)): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError("중복된 숫자를 입력하였습니다") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [int(x) for x in arr_list] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def regame(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val = input("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요.: ") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if val in ["1","2"]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return int(val) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError("1혹은 2를 입력해주세요.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def make_num(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return random.sample(range(1,10),3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def input_num(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return check_valid_input() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def check(com, arr): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 프로그램의 진입점 함수. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 여기에서 전체 프로그램 로직을 시작합니다. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 숫자 야구 게임의 결과를 계산하는 함수 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 같은 위치에 같은 숫자가 있으면 스트라이크 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 다른 위치에 같은 숫자가 있으면 볼 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # 프로그램의 메인 로직을 여기에 구현 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| strikes=0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| balls=0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in range(3): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if arr[i] == com[i]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| strikes += 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if arr[i] in com: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| balls += 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return strikes, balls | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def game(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| com=make_num() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while(1): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arr=input_num() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| strikes, balls = check(com,arr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if strikes==0 and balls==0: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("낫싱") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif strikes==3: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("3스트라이크") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("3개의 숫자를 모두 맞히셨습니다! 게임 종료") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"{balls}볼 {strikes}스트라이크") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def game(): | |
| com=make_num() | |
| while(1): | |
| arr=input_num() | |
| strikes, balls = check(com,arr) | |
| if strikes==0 and balls==0: | |
| print("낫싱") | |
| elif strikes==3: | |
| print("3스트라이크") | |
| print("3개의 숫자를 모두 맞히셨습니다! 게임 종료") | |
| break | |
| else: | |
| print(f"{balls}볼 {strikes}스트라이크") | |
| def game(): | |
| com = make_num() | |
| attempts = 0 | |
| while True: | |
| attempts += 1 | |
| print(f"시도 #{attempts}") | |
| arr = input_num() | |
| strikes, balls = check(com, arr) | |
| if strikes == 0 and balls == 0: | |
| print("낫싱") | |
| elif strikes == 3: | |
| print("3스트라이크") | |
| print(f"3개의 숫자를 모두 맞히셨습니다! (시도 횟수: {attempts})") | |
| print(f"정답은 {com} 이었습니다.") | |
| break | |
| else: | |
| print(f"{balls}볼 {strikes}스트라이크") |
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 43-43: E302 expected 2 blank lines, found 1
[error] 44-44: E225 missing whitespace around operator
[error] 45-45: W293 blank line contains whitespace
[error] 46-46: E275 missing whitespace after keyword
[error] 47-47: E225 missing whitespace around operator
[error] 48-48: E231 missing whitespace after ','
[error] 50-50: E225 missing whitespace around operator
[error] 50-50: E225 missing whitespace around operator
[error] 52-52: E225 missing whitespace around operator
[error] 58-58: W293 blank line contains whitespace
Uh oh!
There was an error while loading. Please reload this page.