랜덤 함수 사용
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
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 승리')