1. 컴퓨터가 무작위로 가위바위보 중 하나를 선택할 코드를 만들어준다
코드)
improt random
rsp = ['가위','바위','보']
computer =random.choice(rsp)
2. 플레이어가 가위바위보 중 하나를 입력할수 있는 코드를 만들어 준다
코드)
player = input('가위, 바위, 보 중 하나를 선택하세요.')
3. 반복문을 설정하고 플레이어와 컴퓨터의 선택을 비교하여 승패를 판정한다.
4. 결과를 출력하여 플레이어가 이겼는지, 컴퓨터가 이겼는지, 비겼는지를 알려줍니다.
-------------------------------------------------------------------------------------------------------------
코드)
while Thue:
computer = random.choice(rsp) - 와일문 안으로 넣어주기
print(computer)
if player not in rsp:
print("다시내세요.")
continue
if player == computer: 해설 : 플레이어와 컴터가 같으면 '무'이다
무+=1
print('무')
elif (computer=='가위' and player=='바위') or 해설 : 컴퓨터 : 가위 플레이어 : 바위
(computer == '바위' and player == '보') or 컴퓨터 : 바위 플레이어 : 보
(computer == '보' and player == '가위') 컴퓨터 : 보 플레이어 :가위
승+=1
print('승') 이면 플레이어 승!
else:
패+=1
print('패') 둘다 아니면 패!
restart =input('다시하기 (Y/N)') ????????????????????
if restark.upper() =='Y' : ????????????????????
continue ???????????????????
else :
print(f"{승}승 {무}무 {패}패")
break 완료
'Daily note' 카테고리의 다른 글
Today I Learned(TIL)-8 (0) | 2024.07.04 |
---|---|
Today I Learned(TIL)-7 (0) | 2024.07.03 |
Today I Learned(TIL)-5 (0) | 2024.07.01 |
Today I Learned(TIL)-4 (0) | 2024.06.28 |
Today I Learned(TIL)-3 (0) | 2024.06.27 |