2019.03.07 Proejct
(TIL은 스스로 이해한 것을 바탕으로 정리한 것으로 오류가 있을 수 있습니다)
# 질문에 답하기.
- 목표에 맞게 가위바위보 게임 만들기
- 잘못된 정보를 입력했을 때 지속적으로 새롭게 실행하도록 만드는 방법
목표
인터페이스
- 가위바위보 게임을 설계한다. 
- 나는 가위, 바위, 보 중에 입력할 수 있도록 한다. (다른 것이 나오면 다시 입력하도록 한다.) 
- 컴퓨터는 랜덤값을 추출하여 가위바위보를 내도록 한다. 
- 매번 할 때 마다 나와 컴퓨터가 무엇이 나왔는지 확인할 수 있도록 하며, 각자의 승을 카운팅 할 수 있도록 한다. 
- 가위바위보는 5판 3선승제 또는 2판 3선승제를 선택할 수 있다. 
- 최종적으로 끝날 경우 누가 이겼는지 나타낸다. 
코드 작성
2.나는 가위,바위,보 중에 입력할 수 있도록 한다.
>>> 
>>> def get_player_choice():
>>> 	while True:
>>> 		get_choice = input("가위 바위 보 중 하나를 내주세요 : ")
>>> 		if get_choice == "가위" or get_choice == "바위" or get_choice == "보":
>>> 			return get_choice
>>> 		else:
>>> 			print("잘못입력하였습니다. 다시 입력해주세요")
>>> 			continue
>>> 
3.컴퓨터는 랜덤값을 추출하여 가위바위보를 내도록 한다.
>>> import random
>>> def get_computer_choice():
>>> 	get_c_choice = random.randint(1,3)   #1부터 3사이에서 랜덤 값 추출
>>> 	if get_c_choice == 1:
>>> 		return "바위"
>>> 	elif get_c_choice == 2:
>>> 		return "가위"
>>> 	elif get_c_choice == 3:
>>> 		return "보"
>>> 
4. 매번 할 때 마다 나와 컴퓨터가 무엇이 나왔는지 확인하며, 승을 카운팅
>>> player1 = 0
>>> computer1 = 0
>>> 
>>> def who_wins(player,computer):
>>> 	global player1
>>> 	global computer1
>>> 	print(f"나 : {player} 컴퓨터 : {computer}") #각자 무엇을 냈는지 받아온다.
>>> 	if player == "바위" and computer == "바위":
>>> 		print("비겼습니다")
>>> 	elif player == "바위" and computer == "가위":
>>> 		print("내가 이겼습니다")
>>> 		player1 += 1
>>> 	elif player == "바위" and computer == "보":
>>> 		print("컴퓨터가 이겼습니다.")
>>> 		computer1 += 1
>>> 	elif player == "가위" and computer == "바위":
>>> 		print("컴퓨터가 이겼습니다.")
>>> 		computer1 += 1
>>> 	elif player == "가위" and computer == "가위":
>>> 		print("비겼습니다.")
>>> 	elif player == "가위" and computer == "보":
>>> 		print("내가 이겼습니다.")
>>> 		player1 += 1
>>> 	elif player == "보" and computer == "바위":
>>> 		print("내가 이겼습니다.")
>>> 		player1 += 1
>>> 	elif player == "보" and computer == "가위":
>>> 		print("컴퓨터가 이겼습니다.")
>>> 		computer1 += 1
>>> 	elif player == "보" and computer == "보":
>>> 		print("비겼습니다.")
>>> 	print(f"나 : {player1} 컴퓨터 : {computer1})
>>> 
5. 6. 5판 3선승제 선택 가능 및 승패 도출
>>> def game():
>>> 	while True:
>>> 		number_of_times = int(input("3판 2승제를 할꺼면 1을, 5판 3승제를 할꺼면 2를 입력해주세요: "))
>>>			if number_of_times == 1:
>>>				while player1 != 2 and computer1 != 2:
>>>					who_wins(get_player_choice(),get_computer_choice())
>>>					if player1 == 2:
>>>						print("내가 이겼습니다. 게임이 끝났습니다.")
>>>						return
>>>					elif computer1 == 2:
>>>						print("컴퓨터가 이겼습니다. 게임이 끝났습니다.")
>>>						return
>>>
>>> 		elif number_of_times == 2:
>>> 			while player1 != 3 and computer1 != 3:
>>>					who_wins(get_player_choice(),get_computer_choice())
>>>					if player1 == 3:
>>>						print("내가 이겼습니다. 게임이 끝났습니다.")
>>>						return
>>>					elif computer1 == 3:
>>>						print("컴퓨터가 이겼습니다. 게임이 끝났습니다.")
>>>						return
>>>
>>>			else:
>>>				print("잘못입력하였습니다. 다시 입력해주세요")
>>>				continue
>>>
