[Python Exam] 가위바위보 게임 예제
2019. 8. 15. 05:15ㆍPython/ㄴ Exam Code
import random
import time
import os
# 만약 가위바위보 게임이 무한반복되게하려면 onwhile 변수의 인자를 "True"로 설정해주면 된다.
onwhile = True
while True:
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
choice = ["가위", "바위", "보"]
print("가위, 바위, 보를 선택해주세요")
for i in range(3):
print(i+1,end=". "+choice[i]+"\n")
userchoice = int(input("-> "))
if userchoice == 1:
userchoice = choice[0]
elif userchoice == 2:
userchoice = choice[1]
elif userchoice == 3:
userchoice = choice[2]
else:
print("잘못 선택하셨습니다.")
time.sleep(1.5)
continue
computerchoice = random.choice(choice)
if userchoice == computerchoice:
print("당신의 선택 : " + userchoice)
print("컴퓨터의 선택 : " + computerchoice)
print("비겼습니다.")
elif userchoice == choice[0]:
if computerchoice == [choice[1]]:
print("당신의 선택 : " + userchoice)
print("컴퓨터의 선택 : " + computerchoice)
print("졌습니다.")
else:
print("당신의 선택 : " + userchoice)
print("컴퓨터의 선택 : " + computerchoice)
print("이겼습니다.")
elif userchoice == choice[1]:
if computerchoice == choice[0]:
print("당신의 선택 : " + userchoice)
print("컴퓨터의 선택 : " + computerchoice)
print("이겼습니다.")
else:
print("당신의 선택 : " + userchoice)
print("컴퓨터의 선택 : " + computerchoice)
print("졌습니다.")
elif userchoice == choice[2]:
if computerchoice == choice[0]:
print("당신의 선택 : " + userchoice)
print("컴퓨터의 선택 : " + computerchoice)
print("졌습니다.")
else:
print("당신의 선택 : " + userchoice)
print("컴퓨터의 선택 : " + computerchoice)
print("이겼습니다.")
if onwhile == True:
time.sleep(1.5)
continue
elif onwhile == False:
break
else:
break
'Python > ㄴ Exam Code' 카테고리의 다른 글
[Python Exam] 파이썬 현재 시간 및 날짜 구하기 (0) | 2019.08.16 |
---|---|
[Python Exam] 구구단 2~9단 (모든 단) 출력하기 예제 (0) | 2019.08.15 |
[Python Exam] 구구단 (한 단) 출력하기 예제 (0) | 2019.08.15 |
[Python Exam] 가위바위보 게임 예제 (0) | 2019.08.15 |
[Python3] 파이썬 화면 캡쳐하기 (2) | 2018.08.08 |
[Python3] 타임스탬프에서 시간빼기(계산) 이전날짜 (0) | 2018.06.28 |
[Python3] 파이썬 시간구하기 (0) | 2018.06.28 |
[Python3] 파이썬 디렉토리 내 파일 존재여부 확인 코드 (0) | 2018.06.26 |
[Python3] 파이썬에서 URL(웹서버)로부터 파일 다운로드하기 (0) | 2018.03.30 |