코딩/파이썬
파이썬 과제 (2). 가위, 바위, 보 게임 만들기
wqk
2024. 3. 19. 16:19
가위, 바위, 보 게임 만들기
- 가위, 바위, 보 중 하나를 입력하세요 : 가위
- 컴퓨터: 바위, 유저: 가위 -> 결과 컴퓨터 승!
import random # random.py
random.random() # 0 <= x < 1 실수
0.1901565427832197
random.random() * 10 # 0 ~ 0.9999999
8.72750317877783
int(random.random() * 10)
9
정답!!
import random
user = input('가위, 바위, 보 중 하나를 입력하세요')
temp = int(random.random()*3)
pc = 0
if temp == 0:
pc = '가위'
elif temp == 1:
pc = '바위'
else :
pc = '보'
if pc == '가위' and user == '바위' or pc == '바위' and user == '보' or pc == '보' and user == '가위' :
print(f'컴퓨터:{pc}, 유저:{user} -> 결과 유저 승!')
elif pc == '가위' and user == '보' or pc == '바위' and user == '가위' or pc == '보' and user == '바위' :
print(f'컴퓨터:{pc}, 유저:{user} -> 결과 컴퓨터 승!')
elif pc == user:
print(f'컴퓨터:{pc}, 유저:{user} -> 결과 비김')
else :
print('다시 입력하세요')