Today I Learned 오늘 한 일 새로운 언어를 배우는 방법
자료형
연산자
제어문, 반복문
함수
call by reference, call by value, call by object reference
First class function인지
Class 지원하는지 (
Encapsulation
Inheritance
Virtual function 지원 여부)
Python Data Type과 기본 Data Structure 실습 Text 가위바위보 게임 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 import randomdef get_player_choice () : """ get_player_choice() -> string Return "바위" or "가위 or "보" """ choice = input("가위바위보! : " ) while choice != "가위" and choice != "바위" and choice != "보" : choice = input("가위바위보! : " ) return choice def get_computer_choice () : """ get_computer_choice -> string Return "바위" or "가위 or "보" """ tup = ("가위" , "바위" , "보" ) return tup[random.randint(0 ,2 )] def who_wins (player, computer) : """ who_wins(player, com) -> string Return if player wins 'player' elif computer wins 'computer' else None """ if player == computer: return None if (player == "바위" and computer == "가위" ) or \ (player == "가위" and computer == "보" ) or \ (player == "보" and computer == "바위" ): return 'player' else : return 'computer' def play_one () : """ play_one -> string Return if player wins 'player' elif computer wins 'computer' """ player_win = 0 computer_win = 0 while player_win == computer_win: player = get_player_choice() computer = get_computer_choice() result = who_wins(player, computer) print(f'Player {player} vs Computer {computer} ' ) if result == 'player' : player_win += 1 elif result == 'computer' : computer_win += 1 if player_win > computer_win: return 'player' else : return 'computer' def check_final_winner (result) : """ check_final_winner(result) -> string result : ex) ['player', 'player'] Return if 'player' >= 2 in result, 'Player' elif 'computer' >=2 in result, 'Computer' else None """ print(f"Player {result.count('player' )} 승 | Computer {result.count('computer' )} 승" ) if result.count('player' ) >= 2 : return 'Player' else : return 'Computer' def play () : """ play() -> None 3판 2선승가위바위보 """ result_list = [] for i in range(3 ): result_list.insert(i, play_one()) print(check_final_winner(result_list)+" Wins!!" ) if __name__=="__main__" : play()
ASCII와 UNICODE ASCII와 UNOCODE의 역사, UNICODE의 Encoding, Decoding 방법도 배웠다.
Python Bubble Sort 1 2 3 4 5 6 7 8 9 10 11 def bubble_sort (li) : n = len(li) for i in range(n-1 ): for j in range(n-1 -i): if li[j] > li[j+1 ]: li[j], li[j+1 ] = li[j+1 ], li[j] if __name__ == "__main__" : li=[6 , 2 , 1 , 4 ] bubble_sort(li) print(li)
간단한 Bubble Sort function을 만들었다.
알고리즘 CodeWars 6kyu. Persistent Bugger
그리고 LeetCode의 Medium Level 문제를 풀려고 했는데 Dynamic Programming 개념이 들어가 쉽지 않다. 주말 내내 풀어야겠다.