Sparta_거북이반_가위바위보_TIL_220916/220919

이태은·2022년 9월 17일
0

회고

목록 보기
20/71
post-thumbnail

가위바위보게임 만들기


  • 랜덤 함수 사용

    from random import choice
    
  • 플레이어 값 받기

    • 일정한 플레이어 값을 받도록 설정

      
      possible_values = ["가위", "바위", "보"]
      
      while True:
         player_value = input("가위, 바위, 보 중에서 내주세요")
      
         if player_value in possible_values:
             break
         else:
             print("제대로 입력하세요.")
      
      print(player_value, "를 선택했습니다!")
      print("게임 진행")

  • 컴퓨터 값 choice를 사용해 랜덤하게 받기
    com_list = ["가위", "바위", "보"]
    com_select = choice(com_list)

  • 결과 출력

    if player_value == com_select:
       print(f' plyer:{player_value}, computer:{com_select},비겼습니다.')
    
    # player가 이긴 경우
    elif player_value == '가위' and com_select=='보':
       print(f' plyer:{player_value}, computer:{com_select}, 게임에서 이겼습니다.')
    elif player_value=='바위' and com_select=='가위':
       print(f' plyer:{player_value}, computer:{com_select}, 게임에서 이겼습니다.')
    elif player_value=='보' and com_select=='바위':
       print(f' plyer:{player_value}, computer:{com_select}, 게임에서 이겼습니다.')
    
    # player가 진 경우
    else:
       print(f' plyer:{player_value}, computer:{com_select}, 게임에서 졌습니다.')


upgrade

3판 2선승제 만들기

  • 매 판마다 점수판 출력하기
  • 먼저 2번 이긴자가 나올시 게임 종료
from random import choice
count_plyaer = 0
count_computer = 0
round = 0


while count_plyaer < 2 and count_computer < 2:
    # 플레이어 값 받기

    possible_values = ["가위", "바위", "보"]

    while True:
        player_value = input(f" round {round+1} ) 가위, 바위, 보 중에서 내주세요")

        if player_value in possible_values:
            break
        else:
            print("제대로 입력하세요.")

    # 컴퓨터 값 설정하기

    com_list = ["가위", "바위", "보"]
    com_select = choice(com_list)
    # print(com_select)


    print( f' player {player_value} vs computer {com_select}')

    # 비긴경우
    if player_value == com_select:
        round +=1
       # print(f' plyer:{player_value}, computer:{com_select},({round} round 비김.)')

    # player가 이긴 경우
    elif player_value == '가위' and com_select=='보':
        round += 1
        #print(f' plyer:{player_value}, computer:{com_select}, ({round} round 승리.)')
        count_plyaer+=1
    elif player_value=='바위' and com_select=='가위':
        round += 1
        #print(f' plyer:{player_value}, computer:{com_select}, ({round} round 승리.)')
        count_plyaer += 1
    elif player_value=='보' and com_select=='바위':
        round += 1
        #print(f' plyer:{player_value}, computer:{com_select}, ({round} round 승리.)')
        count_plyaer += 1
    # player가 진 경우
    else:
        round += 1
        #print(f' plyer:{player_value}, computer:{com_select} ({round} round 패배.)')
        count_computer+=1


    # round 마다 점수 출력
    print(f'player {count_plyaer} : computer {count_computer} ')
    print('===========================================================')


    # 승자 출력

if count_plyaer ==2:
    print('player 승리')
else:
    print('computer 승리')
profile
나는 탱구

0개의 댓글