Last active
August 29, 2015 13:57
-
-
Save allieus/9857649 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
MAP = { | |
('가위', '가위'): 0, | |
('가위', '바위'): -1, | |
('가위', '보'): 1, | |
('바위', '가위'): 1, | |
('바위', '바위'): 0, | |
('바위', '보'): -1, | |
('보', '가위'): -1, | |
('보', '바위'): 1, | |
('보', '보'): 0, | |
} | |
def main(): | |
print("가위바위보 게임을 시작합니다.") | |
print("게임 당 코인이 1coin씩 소모 됩니다.") | |
coin = 10 | |
while True: | |
choice = input("\n가위~바위~보~ (종료: q) : ").strip() | |
if choice == 'q': | |
print("수고하셨습니다.") | |
break | |
computer_choice = random.choice(("가위", "바위", "보")) | |
try: | |
result = MAP[(choice, computer_choice)] | |
print("{} VS {}".format(choice, computer_choice)) | |
if result > 0: | |
coin *= 2 | |
print("이겼습니다. 코인이 두 배가 됩니다. (코인 : {})".format(coin)) | |
elif result < 0: | |
coin -= 1 | |
print("졌습니다. 코인을 하나 잃습니다. (코인 : {})".format(coin)) | |
if coin <= 0: | |
print("코인이 다 떨어졌네요.") | |
break | |
else: | |
print("비겼습니다. 코인을 잃지 않습니다. (코인 : {})".format(coin)) | |
except KeyError: | |
print("가위, 바위, 보 중에 하나만 내주세요.") | |
print("게임을 종료합니다.") | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
위바위보 게임을 시작합니다. | |
게임 당 코인이 1coin씩 소모 됩니다. | |
가위~바위~보~ (종료: q) : 바위 | |
바위 VS 보 | |
졌습니다. 코인을 하나 잃습니다. (코인 : 9) | |
가위~바위~보~ (종료: q) : 가위 | |
가위 VS 바위 | |
졌습니다. 코인을 하나 잃습니다. (코인 : 8) | |
가위~바위~보~ (종료: q) : 보 | |
보 VS 보 | |
비겼습니다. 코인을 잃지 않습니다. (코인 : 8) | |
가위~바위~보~ (종료: q) : 가위 | |
가위 VS 바위 | |
졌습니다. 코인을 하나 잃습니다. (코인 : 7) | |
가위~바위~보~ (종료: q) : 바위 | |
바위 VS 보 | |
졌습니다. 코인을 하나 잃습니다. (코인 : 6) | |
가위~바위~보~ (종료: q) : 보 | |
보 VS 바위 | |
이겼습니다. 코인이 두 배가 됩니다. (코인 : 12) | |
가위~바위~보~ (종료: q) : q | |
수고하셨습니다. | |
게임을 종료합니다. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment