codingnow
Advanced tools
| import random | ||
| # Black 30 \033[30m | ||
| # Red 31 \033[31m | ||
| # Green 32 \033[32m | ||
| # Yellow 33 \033[33m | ||
| # Blue 34 \033[34m | ||
| # White 37 \033[37m | ||
| # 초기화 0 \033[0m (반드시 끝에 넣어줘야 다음 줄에 영향이 없음) | ||
| class Chapter_baseball_game: | ||
| chapter = '야구게임' | ||
| step = 1 | ||
| step_min = 1 | ||
| step_max = 1 | ||
| title = "간단한 게임" | ||
| correct = 0 | ||
| guide_line_max = 50 | ||
| answer_limit_count = 10 | ||
| answer_count = 0 | ||
| strike = 0 | ||
| ball = 0 | ||
| def __init__(self): | ||
| print("\033[32m=" * self.guide_line_max) | ||
| print(f"코딩 테스트 - {self.title} : {self.chapter}") | ||
| print("설명: 같은 자리의 수는 스트라이크, 다른 자리의 수는 볼이 출력됩니다.") | ||
| print(f"현재 챕터는 총 {self.step_max} 단계입니다.") | ||
| print() | ||
| print("사용법:") | ||
| print(" 1. lower = coding.get_option('lower') # 하위값") | ||
| print(" 2. upper = coding.get_option('upper') # 상위값") | ||
| print(" 3. if coding.answer(answer) == False: # 정답을 맞추거나 제한횟수를 넘으면 False 반환") | ||
| print(" 4. result =coding.get() # 현재 결과 값 반환 ('up', 'down', '정답')") | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m",end='') | ||
| print("\n"*1) | ||
| print("\033[34m",end='') | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m") | ||
| def start(self): | ||
| if self.step < self.step_min or self.step > self.step_max: | ||
| print(f"잘못된 단계를 입력했습니다. {self.step_min} ~ {self.step_max}.") | ||
| return | ||
| print("\033[34m",end='') | ||
| print(f"[{self.step} 단계] ",end='') | ||
| print("\033[0m") | ||
| self.strike = 0 | ||
| self.ball = 0 | ||
| self.correct = ''.join(random.sample(['1','2','3','4','5','6','7','8','9'],3)) | ||
| self.answer_limit_count = 100 | ||
| self.answer_count = 0 | ||
| self.is_return_operation = True | ||
| print("\033[34m",end='') | ||
| print(f"[문제 설명] 3자리 숫자를 맞춰보세요! (중복 숫자 없음) ",end='') | ||
| print(f"정답 값: {self.correct}") | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m") | ||
| def get(self): | ||
| return {"strike": self.strike, "ball": self.ball} | ||
| def get_operation(self): | ||
| return {"strike": self.strike, "ball": self.ball} | ||
| def answer(self, answer): | ||
| self.answer_count += 1 | ||
| print(f"\n\033[31m[결과 확인] 입력 값: {answer} 시도횟수 : {self.answer_count}\033[0m") | ||
| # print() | ||
| answer = str(answer) | ||
| self.strike = 0 | ||
| self.ball = 0 | ||
| for i in range(3): | ||
| if answer[i] == self.correct[i]: | ||
| self.strike += 1 | ||
| elif answer[i] in self.correct: | ||
| self.ball += 1 | ||
| print(f"\033[33m스트라이크: {self.strike}, 볼: {self.ball}\033[0m") | ||
| if answer == self.correct: | ||
| print("\033[31m정답!!\033[0m") | ||
| print() | ||
| self.step += 1 | ||
| if self.step > self.step_max: | ||
| print("축하합니다! 모든 단계를 완료했습니다.") | ||
| self.step = self.step_max | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return False | ||
| else: | ||
| print("\033[34m",end='') | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m") | ||
| # print(f"다음 단계로 이동합니다. Step: {self.step}") | ||
| self.next() | ||
| # print() | ||
| return False | ||
| elif self.answer_count >= self.answer_limit_count: | ||
| print(f"\n\033[31m답안 시도 횟수 초과!! 정답은 {self.correct} 입니다.\033[0m") | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return False | ||
| else: | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return True | ||
| def next(self): | ||
| if self.step <= self.step_max: | ||
| self.start() | ||
| else: | ||
| print("이미 마지막 단계입니다.") | ||
| def print_options(self): | ||
| print("\033[33m",end='') | ||
| print() | ||
| print("[옵션 정보]") | ||
| print(f" * operation (현재결과) : {(self.strike, self.ball)}") | ||
| print("\033[0m") | ||
| def get_option(self, cmd): | ||
| if cmd == 'operation': | ||
| return (self.strike, self.ball) | ||
| else: | ||
| return None |
| import random | ||
| # Black 30 \033[30m | ||
| # Red 31 \033[31m | ||
| # Green 32 \033[32m | ||
| # Yellow 33 \033[33m | ||
| # Blue 34 \033[34m | ||
| # White 37 \033[37m | ||
| # 초기화 0 \033[0m (반드시 끝에 넣어줘야 다음 줄에 영향이 없음) | ||
| class Chapter_find_number: | ||
| chapter = '숫자 맞추기' | ||
| step = 1 | ||
| step_min = 1 | ||
| step_max = 1 | ||
| title = "간단한 게임" | ||
| number_lower = 1 | ||
| number_upper = 100 | ||
| correct = 0 | ||
| guide_line_max = 50 | ||
| operation = ['up', 'down','정답'] | ||
| current_operation = '없음' | ||
| is_return_operation = False | ||
| answer_limit_count = 10 | ||
| answer_count = 0 | ||
| def __init__(self): | ||
| print("\033[32m=" * self.guide_line_max) | ||
| print(f"코딩 테스트 - {self.title} : {self.chapter}") | ||
| print("설명: 입력한 숫자보다 크면 'up', 작으면 'down', 같으면 '정답'이 출력됩니다.") | ||
| print(f"출력되는 값 : {self.operation}") | ||
| print(f"현재 챕터는 총 {self.step_max} 단계입니다.") | ||
| print() | ||
| print("사용법:") | ||
| print(" 1. lower = coding.get_option('lower') # 하위값") | ||
| print(" 2. upper = coding.get_option('upper') # 상위값") | ||
| print(" 3. if coding.answer(answer) == False: # 정답을 맞추거나 제한횟수를 넘으면 False 반환") | ||
| print(" 4. result =coding.get() # 현재 결과 값 반환 ('up', 'down', '정답')") | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m",end='') | ||
| print("\n"*1) | ||
| print("\033[34m",end='') | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m") | ||
| def start(self): | ||
| if self.step < self.step_min or self.step > self.step_max: | ||
| print(f"잘못된 단계를 입력했습니다. {self.step_min} ~ {self.step_max}.") | ||
| return | ||
| print("\033[34m",end='') | ||
| print(f"[{self.step} 단계] ",end='') | ||
| print("\033[0m") | ||
| self.problem_idx = 0 | ||
| self.number_upper = (self.step) * 100 | ||
| self.correct = random.randint(self.number_lower, self.number_upper) | ||
| self.answer_limit_count = 10 | ||
| self.answer_count = 0 | ||
| self.is_return_operation = True | ||
| print("\033[34m",end='') | ||
| print(f"[문제 설명] 주어진 숫자를 맞추세요. 숫자는 {self.number_lower} 부터 {self.number_upper} 사이입니다.") | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m") | ||
| def get(self): | ||
| return self.current_operation | ||
| def get_operation(self): | ||
| return self.current_operation | ||
| def answer(self, answer): | ||
| self.answer_count += 1 | ||
| print(f"\n\033[31m[결과 확인] 입력 값: {answer} 시도횟수 : {self.answer_count}\033[0m") | ||
| # print(f"정답 값: {self.correct}") | ||
| # print() | ||
| if answer == self.correct: | ||
| print("\033[31m정답!!\033[0m") | ||
| print() | ||
| self.step += 1 | ||
| if self.step > self.step_max: | ||
| print("축하합니다! 모든 단계를 완료했습니다.") | ||
| self.step = self.step_max | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return False | ||
| else: | ||
| print("\033[34m",end='') | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m") | ||
| # print(f"다음 단계로 이동합니다. Step: {self.step}") | ||
| self.next() | ||
| # print() | ||
| return False | ||
| elif self.answer_count >= self.answer_limit_count: | ||
| print(f"\n\033[31m답안 시도 횟수 초과!! 정답은 {self.correct} 입니다.\033[0m") | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return False | ||
| elif answer < self.correct: | ||
| self.current_operation = 'up' | ||
| print("\033[33mup\033[0m") | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return True | ||
| else: | ||
| self.current_operation = 'down' | ||
| print("\033[33mdown\033[0m") | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return True | ||
| def next(self): | ||
| if self.step <= self.step_max: | ||
| self.start() | ||
| else: | ||
| print("이미 마지막 단계입니다.") | ||
| def print_options(self): | ||
| print("\033[33m",end='') | ||
| print() | ||
| print("[옵션 정보]") | ||
| print(f" * operation (현재결과) : {self.current_operation}") | ||
| print(f" * lower (하위값): {self.number_lower}") | ||
| print(f" * upper (상위값): {self.number_upper}",end='') | ||
| print("\033[0m") | ||
| def get_option(self, cmd): | ||
| if cmd == 'operation': | ||
| return self.current_operation | ||
| elif cmd == 'lower': | ||
| return self.number_lower | ||
| elif cmd == 'upper': | ||
| return self.number_upper | ||
| else: | ||
| return None |
| import codingnow | ||
| coding = codingnow.CodingTest() | ||
| coding.start(2) | ||
| values = [] | ||
| while True: | ||
| value = coding.get() | ||
| if value == 'END': | ||
| break | ||
| values.append(value) | ||
| print(values) |
| # import os | ||
| # os.system('pip install codingnow --upgrade') | ||
| from codingnow.learning.coding.codingTest import * | ||
| coding = CodingTest() | ||
| coding.start(chapter=2) | ||
| coding.print_options() | ||
| oop = coding.get_option('operation') | ||
| print('oop:', oop) | ||
| length = coding.get_option('length') | ||
| print('length:', length) |
| # import os | ||
| # os.system('pip install codingnow --upgrade') | ||
| from codingnow.learning.coding.codingTest import * | ||
| coding = CodingTest() | ||
| coding.start(chapter=2) | ||
| #최대 값 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| if a > b: | ||
| c = a | ||
| else: | ||
| c = b | ||
| coding.answer(c) | ||
| #최소 값 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| if a < b: | ||
| c = a | ||
| else: | ||
| c = b | ||
| coding.answer(c) | ||
| #짝수개수 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| cnt = 0 | ||
| if a % 2 == 0: | ||
| cnt += 1 | ||
| if b % 2 == 0: | ||
| cnt += 1 | ||
| coding.answer(cnt) | ||
| #짝수개수 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| cnt = 0 | ||
| if a % 2 == 1: | ||
| cnt += 1 | ||
| if b % 2 == 1: | ||
| cnt += 1 | ||
| coding.answer(cnt) | ||
| #합계 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| c = a + b | ||
| coding.answer(c) | ||
| #평균 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| c = a + b | ||
| c = c / 2 | ||
| coding.answer(c) |
| # import os | ||
| # os.system('pip install codingnow --upgrade') | ||
| from codingnow.learning.coding.codingTest import * | ||
| coding = CodingTest() | ||
| coding.start(chapter=2) | ||
| while True: | ||
| values = [] | ||
| op = '' | ||
| while True: | ||
| value = coding.get() | ||
| if value == 'END': | ||
| break | ||
| if value in ['최대', '최소', '짝수개수', '홀수개수', '합계', '평균']: | ||
| op = value | ||
| continue | ||
| values.append(value) | ||
| if op == '최대': | ||
| answer = max(values) | ||
| elif op == '최소': | ||
| answer = min(values) | ||
| elif op == '짝수개수': | ||
| answer = sum(1 for v in values if v % 2 == 0) | ||
| elif op == '홀수개수': | ||
| answer = sum(1 for v in values if v % 2 == 1) | ||
| elif op == '합계': | ||
| answer = sum(values) | ||
| elif op == '평균': | ||
| answer = sum(values) / len(values) | ||
| result = coding.answer(answer) | ||
| if result: | ||
| continue | ||
| else: | ||
| break |
| Metadata-Version: 2.1 | ||
| Name: codingnow | ||
| Version: 0.1.51 | ||
| Version: 0.1.52 | ||
| Summary: A simple example Python package | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/cflab2017/codingnow_py |
@@ -68,3 +68,4 @@ LICENSE | ||
| codingnow/learning/coding/Chapters/chapter_03.py | ||
| codingnow/learning/coding/Chapters/chapter_04.py | ||
| codingnow/learning/coding/Chapters/chapter_baseball_game.py | ||
| codingnow/learning/coding/Chapters/chapter_find_number.py | ||
| codingnow/learning/coding/example/__init__.py | ||
@@ -77,5 +78,9 @@ codingnow/learning/coding/example/Chapter_01/__init__.py | ||
| codingnow/learning/coding/example/Chapter_02/__init__.py | ||
| codingnow/learning/coding/example/Chapter_02/main_00.py | ||
| codingnow/learning/coding/example/Chapter_02/main_01.py | ||
| codingnow/learning/coding/example/Chapter_02/main_02.py | ||
| codingnow/learning/coding/example/Chapter_02/main_03.py | ||
| codingnow/learning/coding/example/Chapter_03/__init__.py | ||
| codingnow/learning/coding/example/Chapter_03/main_00.py | ||
| codingnow/learning/coding/example/Chapter_03/main_01.py | ||
| codingnow/learning/coding/example/Chapter_03/main_02.py | ||
| codingnow/learning/exam_led_ctrl/exam_0.py | ||
@@ -82,0 +87,0 @@ codingnow/learning/exam_led_ctrl/exam_1.py |
| from codingnow.learning.coding.Chapters.chapter_01 import * | ||
| from codingnow.learning.coding.Chapters.chapter_02 import * | ||
| from codingnow.learning.coding.Chapters.chapter_03 import * | ||
| from codingnow.learning.coding.Chapters.chapter_04 import * | ||
| from codingnow.learning.coding.Chapters.chapter_find_number import * | ||
| from codingnow.learning.coding.Chapters.chapter_baseball_game import * | ||
@@ -10,3 +11,6 @@ class CodingTest: | ||
| def __init__(self): | ||
| pass | ||
| print() | ||
| print("\033[31m",end='') | ||
| print("코딩 테스트 시작 1~5",end='') | ||
| print("\033[0m") | ||
@@ -25,4 +29,7 @@ def start(self,chapter): | ||
| elif self.chapter == 4: | ||
| self.instance = Chapter_04() | ||
| self.instance = Chapter_find_number() | ||
| self.instance.start() | ||
| elif self.chapter == 5: | ||
| self.instance = Chapter_baseball_game() | ||
| self.instance.start() | ||
| else: | ||
@@ -32,2 +39,5 @@ print("해당 챕터는 준비중입니다.") | ||
| def get(self): | ||
| print(" \033[34m",end='') | ||
| print("get -> ",end='') | ||
| print("\033[0m",end='') | ||
| return self.instance.get() | ||
@@ -34,0 +44,0 @@ |
@@ -30,2 +30,3 @@ import random | ||
| print("설명: 주어진 숫자의 사칙연산 값을 구하세요.") | ||
| print(f"{self.operation}") | ||
| print(f"현재 챕터는 총 {self.step_max} 단계입니다.") | ||
@@ -97,3 +98,3 @@ print() | ||
| print("\033[33m",end='') | ||
| print(f" 연산자: {self.current_operation}",end='') | ||
| print(f"{self.current_operation}",end='') | ||
| print("\033[0m") | ||
@@ -104,3 +105,3 @@ self.is_return_operation = False | ||
| print("\033[33m",end='') | ||
| print(f" END",end='') | ||
| print(f"END",end='') | ||
| print("\033[0m") | ||
@@ -112,3 +113,3 @@ return 'END' | ||
| print("\033[33m",end='') | ||
| print(f" 문제값: {value}",end='') | ||
| print(f"{value}",end='') | ||
| print("\033[0m") | ||
@@ -115,0 +116,0 @@ self.problem_idx += 1 |
@@ -15,4 +15,4 @@ import random | ||
| step_min = 1 | ||
| step_max = 20 | ||
| title = "조건문과 비교연산" | ||
| step_max = 6 | ||
| title = "리스트 사용법 익히기" | ||
| problem_lst = [] | ||
@@ -22,4 +22,4 @@ problem_idx = 0 | ||
| guide_line_max = 50 | ||
| operation = ['최대', '최소','짝수개수', '홀수개수', '합계','평균'] | ||
| current_operation = '최대' | ||
| operation = ['추가', '길이', '합', '평균', '짝수합', '홀수합'] | ||
| current_operation = 'append' | ||
| is_return_operation = False | ||
@@ -31,3 +31,3 @@ | ||
| print(f"코딩 테스트 - Chapter {self.chapter}: {self.title}") | ||
| print("설명: 주어진 숫자의 조건문과 비교연산을 사용하세요.") | ||
| print("설명: 리스트를 생성하고 다양한 연산을 사용하세요.") | ||
| print(f"{self.operation}를 구합니다.") | ||
@@ -61,36 +61,61 @@ print(f"현재 챕터는 총 {self.step_max} 단계입니다.") | ||
| if self.step <= 6: | ||
| self.problem_lst = [random.randint(10,100) for _ in range(2) ] | ||
| self.current_operation = self.operation[self.step - 1] | ||
| elif self.step <= 12: | ||
| self.problem_lst = [random.randint(10,100) for _ in range(4) ] | ||
| self.current_operation = self.operation[(self.step - 1) % 6] | ||
| else: | ||
| self.problem_lst = [random.randint(10,100) for _ in range(10) ] | ||
| self.current_operation = random.choice(self.operation) | ||
| print("\033[31m",end='') | ||
| print("현재 단계는 랜덤 연산자 단계입니다.",end='') | ||
| print("\033[0m") | ||
| self.problem_lst = [random.randint(10,100) for _ in range(random.randint(10,20)) ] | ||
| self.current_operation = self.operation[self.step - 1] | ||
| # elif self.step <= 12: | ||
| # self.problem_lst = [random.randint(10,100) for _ in range(20) ] | ||
| # self.current_operation = self.operation[(self.step - 1) % 6] | ||
| # else: | ||
| # self.problem_lst = [random.randint(10,100) for _ in range(30) ] | ||
| # self.current_operation = random.choice(self.operation) | ||
| # print("\033[31m",end='') | ||
| # print("현재 단계는 랜덤 연산자 단계입니다.",end='') | ||
| # print("\033[0m") | ||
| self.is_return_operation = True | ||
| print("\033[34m",end='') | ||
| if self.current_operation == '최대': | ||
| print("주어진 숫자 중 최대값을 구하세요.") | ||
| self.correct = max(self.problem_lst) | ||
| elif self.current_operation == '최소': | ||
| print("주어진 숫자 중 최소값을 구하세요.") | ||
| self.correct = min(self.problem_lst) | ||
| elif self.current_operation == '짝수개수': | ||
| print("주어진 숫자 중 짝수의 개수를 구하세요.") | ||
| self.correct = sum(1 for x in self.problem_lst if x % 2 == 0) | ||
| elif self.current_operation == '홀수개수': | ||
| print("주어진 숫자 중 홀수의 개수를 구하세요.") | ||
| self.correct = sum(1 for x in self.problem_lst if x % 2 != 0) | ||
| elif self.current_operation == '합계': | ||
| print("주어진 숫자의 합계를 구하세요.") | ||
| if self.current_operation == '추가': | ||
| print("주어진 숫자를 리스트에 추가하고 리스트를 반환하세요.") | ||
| print() | ||
| print(f" 힌트") | ||
| print(f" values = [] # 빈 리스트 생성") | ||
| print(f" values.append(value) # 리스트에 값 추가") | ||
| print() | ||
| self.correct = self.problem_lst | ||
| elif self.current_operation == '합': | ||
| print("리스트에 있는 숫자들의 합계를 구하세요.") | ||
| print() | ||
| print(f" 힌트") | ||
| print(f" result = sum(values) # 리스트의 합구하기") | ||
| print() | ||
| self.correct = sum(self.problem_lst) | ||
| elif self.current_operation == '평균': | ||
| print("주어진 숫자의 평균값을 구하세요.") | ||
| print("리스트에 있는 숫자들의 평균값을 구하세요.") | ||
| self.correct = sum(self.problem_lst) / len(self.problem_lst) | ||
| elif self.current_operation == '길이': | ||
| print("리스트에 있는 숫자들의 개수를 구하세요.") | ||
| print() | ||
| print(f" 힌트") | ||
| print(f" result = len(values) # 리스트의 길이 구하기") | ||
| print() | ||
| self.correct = len(self.problem_lst) | ||
| elif self.current_operation == '짝수합': | ||
| print("리스트에 있는 숫자들 중 짝수 값들의 합계를 구하세요.") | ||
| print() | ||
| print(f" 힌트") | ||
| print(f" for val in values: # 리스트에서 한개씩 값 꺼내기") | ||
| print() | ||
| self.correct = sum(x for x in self.problem_lst if x % 2 == 0) | ||
| elif self.current_operation == '홀수합': | ||
| print("리스트에 있는 숫자들 중 홀수 값들의 합계를 구하세요.") | ||
| print() | ||
| print(f" 힌트") | ||
| print(f" for val in values: # 리스트에서 한개씩 값 꺼내기") | ||
| print() | ||
| self.correct = sum(x for x in self.problem_lst if x % 2 != 0) | ||
| # elif self.current_operation == 'del': | ||
| # print("리스트에 있는 숫자들 중 짝수 값을 모두 삭제한 리스트를 구하세요.") | ||
| # self.correct = [x for x in self.problem_lst if x % 2 != 0] | ||
| print(f" * 문제값 : {len(self.problem_lst)}개") | ||
@@ -105,3 +130,3 @@ print(f" * 연산자 : 1개") | ||
| print("\033[33m",end='') | ||
| print(f" 연산자: {self.current_operation}",end='') | ||
| print(f"{self.current_operation}",end='') | ||
| print("\033[0m") | ||
@@ -112,3 +137,3 @@ self.is_return_operation = False | ||
| print("\033[33m",end='') | ||
| print(f" END",end='') | ||
| print(f"END",end='') | ||
| print("\033[0m") | ||
@@ -120,3 +145,3 @@ return 'END' | ||
| print("\033[33m",end='') | ||
| print(f" 문제값: {value}",end='') | ||
| print(f"{value}",end='') | ||
| print("\033[0m") | ||
@@ -129,5 +154,6 @@ self.problem_idx += 1 | ||
| def answer(self, answer): | ||
| def answer(self, answer:list): | ||
| print(f"\n\033[31m[결과 확인]\n 입력 값: {answer}\n 정답 값: {self.correct}\033[0m") | ||
| print() | ||
| if answer == self.correct: | ||
@@ -134,0 +160,0 @@ print("정답!!") |
@@ -15,28 +15,25 @@ import random | ||
| step_min = 1 | ||
| step_max = 1 | ||
| title = "간단한 게임 : 숫자 맞추기" | ||
| number_lower = 1 | ||
| number_upper = 100 | ||
| step_max = 20 | ||
| title = "조건문과 비교연산" | ||
| problem_lst = [] | ||
| problem_idx = 0 | ||
| correct = 0 | ||
| guide_line_max = 50 | ||
| operation = ['up', 'down','정답'] | ||
| current_operation = '없음' | ||
| operation = ['최대', '최소','짝수개수', '홀수개수', '합계','평균'] | ||
| current_operation = '최대' | ||
| is_return_operation = False | ||
| answer_limit_count = 10 | ||
| answer_count = 0 | ||
| def __init__(self): | ||
| print("\033[32m=" * self.guide_line_max) | ||
| print(f"코딩 테스트 - Chapter {self.chapter}: {self.title}") | ||
| print("설명: 입력한 숫자보다 크면 'up', 작으면 'down', 같으면 '정답'이 출력됩니다.") | ||
| print(f"출력되는 값 : {self.operation}") | ||
| print("설명: 주어진 숫자의 조건문과 비교연산을 사용하세요.") | ||
| print(f"{self.operation}를 구합니다.") | ||
| print(f"현재 챕터는 총 {self.step_max} 단계입니다.") | ||
| print() | ||
| print("사용법:") | ||
| print(" 1. lower = coding.get_option('lower') # 하위값") | ||
| print(" 2. upper = coding.get_option('upper') # 상위값") | ||
| print(" 3. if coding.answer(answer) == False: # 정답을 맞추거나 제한횟수를 넘으면 False 반환") | ||
| print(" 4. result =coding.get() # 현재 결과 값 반환 ('up', 'down', '정답')") | ||
| print(" 1. result = coding.get() # 생성된 문제값을 순서대로 반환, 반환값이 없으면 'END' 반환") | ||
| print(" 2. if coding.answer(answer) == False: # 틀리거나 모든 문제를 통과하면 False 반환") | ||
| print(" 3. coding.print_options() # 사용가능한 옵션 정보 출력") | ||
| print(" 4. value = coding.get_option(cmd) # 옵션값 반환 (cmd: operation, length)") | ||
@@ -62,10 +59,38 @@ print("=" * self.guide_line_max,end='') | ||
| self.number_upper = (self.step) * 100 | ||
| self.correct = random.randint(self.number_lower, self.number_upper) | ||
| self.answer_limit_count = 10 | ||
| self.answer_count = 0 | ||
| if self.step <= 6: | ||
| self.problem_lst = [random.randint(10,100) for _ in range(2) ] | ||
| self.current_operation = self.operation[self.step - 1] | ||
| elif self.step <= 12: | ||
| self.problem_lst = [random.randint(10,100) for _ in range(4) ] | ||
| self.current_operation = self.operation[(self.step - 1) % 6] | ||
| else: | ||
| self.problem_lst = [random.randint(10,100) for _ in range(10) ] | ||
| self.current_operation = random.choice(self.operation) | ||
| print("\033[31m",end='') | ||
| print("현재 단계는 랜덤 연산자 단계입니다.",end='') | ||
| print("\033[0m") | ||
| self.is_return_operation = True | ||
| print("\033[34m",end='') | ||
| print(f"[문제 설명] 주어진 숫자를 맞추세요. 숫자는 {self.number_lower} 부터 {self.number_upper} 사이입니다.") | ||
| if self.current_operation == '최대': | ||
| print("주어진 숫자 중 최대값을 구하세요.") | ||
| self.correct = max(self.problem_lst) | ||
| elif self.current_operation == '최소': | ||
| print("주어진 숫자 중 최소값을 구하세요.") | ||
| self.correct = min(self.problem_lst) | ||
| elif self.current_operation == '짝수개수': | ||
| print("주어진 숫자 중 짝수의 개수를 구하세요.") | ||
| self.correct = sum(1 for x in self.problem_lst if x % 2 == 0) | ||
| elif self.current_operation == '홀수개수': | ||
| print("주어진 숫자 중 홀수의 개수를 구하세요.") | ||
| self.correct = sum(1 for x in self.problem_lst if x % 2 != 0) | ||
| elif self.current_operation == '합계': | ||
| print("주어진 숫자의 합계를 구하세요.") | ||
| self.correct = sum(self.problem_lst) | ||
| elif self.current_operation == '평균': | ||
| print("주어진 숫자의 평균값을 구하세요.") | ||
| self.correct = sum(self.problem_lst) / len(self.problem_lst) | ||
| print(f" * 문제값 : {len(self.problem_lst)}개") | ||
| print(f" * 연산자 : 1개") | ||
| print("=" * self.guide_line_max,end='') | ||
@@ -75,3 +100,22 @@ print("\033[0m") | ||
| def get(self): | ||
| return self.current_operation | ||
| if self.problem_idx >= len(self.problem_lst): | ||
| if self.is_return_operation: | ||
| print("\033[33m",end='') | ||
| print(f"{self.current_operation}",end='') | ||
| print("\033[0m") | ||
| self.is_return_operation = False | ||
| return self.current_operation | ||
| print("\033[33m",end='') | ||
| print(f"END",end='') | ||
| print("\033[0m") | ||
| return 'END' | ||
| value = self.problem_lst[self.problem_idx] | ||
| print("\033[33m",end='') | ||
| print(f"{value}",end='') | ||
| print("\033[0m") | ||
| self.problem_idx += 1 | ||
| return value | ||
@@ -82,8 +126,6 @@ def get_operation(self): | ||
| def answer(self, answer): | ||
| self.answer_count += 1 | ||
| print(f"\n\033[31m[결과 확인] 입력 값: {answer} 시도횟수 : {self.answer_count}\033[0m") | ||
| # print(f"정답 값: {self.correct}") | ||
| # print() | ||
| print(f"\n\033[31m[결과 확인]\n 입력 값: {answer}\n 정답 값: {self.correct}\033[0m") | ||
| print() | ||
| if answer == self.correct: | ||
| print("\033[31m정답!!\033[0m") | ||
| print("정답!!") | ||
| print() | ||
@@ -98,3 +140,4 @@ | ||
| return False | ||
| else: | ||
| else: | ||
| print("\033[34m",end='') | ||
@@ -106,20 +149,8 @@ print("=" * self.guide_line_max,end='') | ||
| # print() | ||
| return False | ||
| elif self.answer_count >= self.answer_limit_count: | ||
| print(f"\n\033[31m답안 시도 횟수 초과!! 정답은 {self.correct} 입니다.\033[0m") | ||
| return True | ||
| else: | ||
| print(f"오답!! 정답은 {self.correct} 입니다.") | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return False | ||
| elif answer < self.correct: | ||
| self.current_operation = 'up' | ||
| print("\033[33mup\033[0m") | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return True | ||
| else: | ||
| self.current_operation = 'down' | ||
| print("\033[33mdown\033[0m") | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return True | ||
@@ -137,5 +168,4 @@ def next(self): | ||
| print("[옵션 정보]") | ||
| print(f" * operation (현재결과) : {self.current_operation}") | ||
| print(f" * lower (하위값): {self.number_lower}") | ||
| print(f" * upper (상위값): {self.number_upper}",end='') | ||
| print(f" * operation (현재 연산자): {self.current_operation}") | ||
| print(f" * length (문제값 개수): {len(self.problem_lst)}",end='') | ||
| print("\033[0m") | ||
@@ -146,7 +176,5 @@ | ||
| return self.current_operation | ||
| elif cmd == 'lower': | ||
| return self.number_lower | ||
| elif cmd == 'upper': | ||
| return self.number_upper | ||
| elif cmd == 'length': | ||
| return len(self.problem_lst) | ||
| else: | ||
| return None |
| from codingnow.learning.coding.Chapters.chapter_01 import * | ||
| from codingnow.learning.coding.Chapters.chapter_02 import * | ||
| from codingnow.learning.coding.Chapters.chapter_03 import * | ||
| from codingnow.learning.coding.Chapters.chapter_04 import * | ||
| from codingnow.learning.coding.Chapters.chapter_find_number import * | ||
| from codingnow.learning.coding.Chapters.chapter_baseball_game import * | ||
@@ -10,3 +11,6 @@ class CodingTest: | ||
| def __init__(self): | ||
| pass | ||
| print() | ||
| print("\033[31m",end='') | ||
| print("코딩 테스트 시작 1~5",end='') | ||
| print("\033[0m") | ||
@@ -25,4 +29,7 @@ def start(self,chapter): | ||
| elif self.chapter == 4: | ||
| self.instance = Chapter_04() | ||
| self.instance = Chapter_find_number() | ||
| self.instance.start() | ||
| elif self.chapter == 5: | ||
| self.instance = Chapter_baseball_game() | ||
| self.instance.start() | ||
| else: | ||
@@ -32,2 +39,5 @@ print("해당 챕터는 준비중입니다.") | ||
| def get(self): | ||
| print(" \033[34m",end='') | ||
| print("get -> ",end='') | ||
| print("\033[0m",end='') | ||
| return self.instance.get() | ||
@@ -34,0 +44,0 @@ |
@@ -1,64 +0,5 @@ | ||
| # import os | ||
| # os.system('pip install codingnow --upgrade') | ||
| from codingnow.learning.coding.codingTest import * | ||
| import codingnow | ||
| coding = CodingTest() | ||
| coding.start(chapter=2) | ||
| coding = codingnow.CodingTest() | ||
| coding.start(2) | ||
| #최대 값 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| if a > b: | ||
| c = a | ||
| else: | ||
| c = b | ||
| coding.answer(c) | ||
| #최소 값 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| if a < b: | ||
| c = a | ||
| else: | ||
| c = b | ||
| coding.answer(c) | ||
| #짝수개수 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| cnt = 0 | ||
| if a % 2 == 0: | ||
| cnt += 1 | ||
| if b % 2 == 0: | ||
| cnt += 1 | ||
| coding.answer(cnt) | ||
| #짝수개수 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| cnt = 0 | ||
| if a % 2 == 1: | ||
| cnt += 1 | ||
| if b % 2 == 1: | ||
| cnt += 1 | ||
| coding.answer(cnt) | ||
| #합계 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| c = a + b | ||
| coding.answer(c) | ||
| #평균 | ||
| a = coding.get() | ||
| b = coding.get() | ||
| c = a + b | ||
| c = c / 2 | ||
| coding.answer(c) |
@@ -1,12 +0,11 @@ | ||
| # import os | ||
| # os.system('pip install codingnow --upgrade') | ||
| from codingnow.learning.coding.codingTest import * | ||
| import codingnow | ||
| coding = CodingTest() | ||
| coding.start(chapter=2) | ||
| coding = codingnow.CodingTest() | ||
| coding.start(2) | ||
| while True: | ||
| values = [] | ||
| op = '' | ||
| result = 0 | ||
| while True: | ||
@@ -16,26 +15,23 @@ value = coding.get() | ||
| break | ||
| if value in ['최대', '최소', '짝수개수', '홀수개수', '합계', '평균']: | ||
| if value in ['추가', '합', '평균', '길이', '짝수합', '홀수합']: | ||
| op = value | ||
| continue | ||
| values.append(value) | ||
| if op == '최대': | ||
| answer = max(values) | ||
| elif op == '최소': | ||
| answer = min(values) | ||
| elif op == '짝수개수': | ||
| answer = sum(1 for v in values if v % 2 == 0) | ||
| elif op == '홀수개수': | ||
| answer = sum(1 for v in values if v % 2 == 1) | ||
| elif op == '합계': | ||
| answer = sum(values) | ||
| values.append(value) | ||
| if op == '추가': | ||
| result = values | ||
| elif op == '합': | ||
| result = sum(values) | ||
| elif op == '평균': | ||
| answer = sum(values) / len(values) | ||
| result = sum(values) / len(values) if values else 0 | ||
| elif op == '길이': | ||
| result = len(values) | ||
| elif op == '짝수합': | ||
| result = sum(v for v in values if v % 2 == 0) | ||
| elif op == '홀수합': | ||
| result = sum(v for v in values if v % 2 != 0) | ||
| if coding.answer(result) == False: | ||
| break | ||
| result = coding.answer(answer) | ||
| if result: | ||
| continue | ||
| else: | ||
| break |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: codingnow | ||
| Version: 0.1.51 | ||
| Version: 0.1.52 | ||
| Summary: A simple example Python package | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/cflab2017/codingnow_py |
+1
-1
@@ -5,3 +5,3 @@ from setuptools import setup, find_packages | ||
| name='codingnow', | ||
| version='0.1.51', | ||
| version='0.1.52', | ||
| author='codingnow', | ||
@@ -8,0 +8,0 @@ author_email='codingnow@naver.com', |
| import random | ||
| # Black 30 \033[30m | ||
| # Red 31 \033[31m | ||
| # Green 32 \033[32m | ||
| # Yellow 33 \033[33m | ||
| # Blue 34 \033[34m | ||
| # White 37 \033[37m | ||
| # 초기화 0 \033[0m (반드시 끝에 넣어줘야 다음 줄에 영향이 없음) | ||
| class Chapter_04: | ||
| chapter = 4 | ||
| step = 1 | ||
| step_min = 1 | ||
| step_max = 1 | ||
| title = "간단한 게임 : 야구게임" | ||
| correct = 0 | ||
| guide_line_max = 50 | ||
| answer_limit_count = 10 | ||
| answer_count = 0 | ||
| strike = 0 | ||
| ball = 0 | ||
| def __init__(self): | ||
| print("\033[32m=" * self.guide_line_max) | ||
| print(f"코딩 테스트 - Chapter {self.chapter}: {self.title}") | ||
| print("설명: 같은 자리의 수는 스트라이크, 다른 자리의 수는 볼이 출력됩니다.") | ||
| print(f"현재 챕터는 총 {self.step_max} 단계입니다.") | ||
| print() | ||
| print("사용법:") | ||
| print(" 1. lower = coding.get_option('lower') # 하위값") | ||
| print(" 2. upper = coding.get_option('upper') # 상위값") | ||
| print(" 3. if coding.answer(answer) == False: # 정답을 맞추거나 제한횟수를 넘으면 False 반환") | ||
| print(" 4. result =coding.get() # 현재 결과 값 반환 ('up', 'down', '정답')") | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m",end='') | ||
| print("\n"*1) | ||
| print("\033[34m",end='') | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m") | ||
| def start(self): | ||
| if self.step < self.step_min or self.step > self.step_max: | ||
| print(f"잘못된 단계를 입력했습니다. {self.step_min} ~ {self.step_max}.") | ||
| return | ||
| print("\033[34m",end='') | ||
| print(f"[{self.step} 단계] ",end='') | ||
| print("\033[0m") | ||
| self.strike = 0 | ||
| self.ball = 0 | ||
| self.correct = ''.join(random.sample(['1','2','3','4','5','6','7','8','9'],3)) | ||
| self.answer_limit_count = 100 | ||
| self.answer_count = 0 | ||
| self.is_return_operation = True | ||
| print("\033[34m",end='') | ||
| print(f"[문제 설명] 3자리 숫자를 맞춰보세요! (중복 숫자 없음) ",end='') | ||
| print(f"정답 값: {self.correct}") | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m") | ||
| def get(self): | ||
| return {"strike": self.strike, "ball": self.ball} | ||
| def get_operation(self): | ||
| return {"strike": self.strike, "ball": self.ball} | ||
| def answer(self, answer): | ||
| self.answer_count += 1 | ||
| print(f"\n\033[31m[결과 확인] 입력 값: {answer} 시도횟수 : {self.answer_count}\033[0m") | ||
| # print() | ||
| answer = str(answer) | ||
| self.strike = 0 | ||
| self.ball = 0 | ||
| for i in range(3): | ||
| if answer[i] == self.correct[i]: | ||
| self.strike += 1 | ||
| elif answer[i] in self.correct: | ||
| self.ball += 1 | ||
| print(f"\033[33m스트라이크: {self.strike}, 볼: {self.ball}\033[0m") | ||
| if answer == self.correct: | ||
| print("\033[31m정답!!\033[0m") | ||
| print() | ||
| self.step += 1 | ||
| if self.step > self.step_max: | ||
| print("축하합니다! 모든 단계를 완료했습니다.") | ||
| self.step = self.step_max | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return False | ||
| else: | ||
| print("\033[34m",end='') | ||
| print("=" * self.guide_line_max,end='') | ||
| print("\033[0m") | ||
| # print(f"다음 단계로 이동합니다. Step: {self.step}") | ||
| self.next() | ||
| # print() | ||
| return False | ||
| elif self.answer_count >= self.answer_limit_count: | ||
| print(f"\n\033[31m답안 시도 횟수 초과!! 정답은 {self.correct} 입니다.\033[0m") | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return False | ||
| else: | ||
| print("=" * self.guide_line_max) | ||
| print() | ||
| return True | ||
| def next(self): | ||
| if self.step <= self.step_max: | ||
| self.start() | ||
| else: | ||
| print("이미 마지막 단계입니다.") | ||
| def print_options(self): | ||
| print("\033[33m",end='') | ||
| print() | ||
| print("[옵션 정보]") | ||
| print(f" * operation (현재결과) : {(self.strike, self.ball)}") | ||
| print("\033[0m") | ||
| def get_option(self, cmd): | ||
| if cmd == 'operation': | ||
| return (self.strike, self.ball) | ||
| else: | ||
| return None |
| # import os | ||
| # os.system('pip install codingnow --upgrade') | ||
| from codingnow.learning.coding.codingTest import * | ||
| coding = CodingTest() | ||
| coding.start(chapter=2) | ||
| coding.print_options() | ||
| oop = coding.get_option('operation') | ||
| print('oop:', oop) | ||
| length = coding.get_option('length') | ||
| print('length:', length) |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
261838
4.06%98
5.38%4140
5.96%