상세 컨텐츠

본문 제목

가위 바위 보 게임 파이썬 코드

시사경제지식

by 브로마리 2023. 8. 25. 02:00

본문

반응형

import random

def get_user_choice():
    choice = input("가위, 바위, 보 중 하나를 선택하세요: ").strip().lower()
    if choice not in ["가위", "바위", "보"]:
        print("올바른 선택이 아닙니다. 다시 시도하세요.")
        return get_user_choice()
    return choice

def get_computer_choice():
    choices = ["가위", "바위", "보"]
    return random.choice(choices)

def determine_winner(user_choice, computer_choice):
    if user_choice == computer_choice:
        return "무승부"
    elif (
        (user_choice == "가위" and computer_choice == "보") or
        (user_choice == "바위" and computer_choice == "가위") or
        (user_choice == "보" and computer_choice == "바위")
    ):
        return "사용자 승리"
    else:
        return "컴퓨터 승리"

def main():
    print("가위 바위 보 게임을 시작합니다.")
    while True:
        user_choice = get_user_choice()
        computer_choice = get_computer_choice()
        print(f"사용자: {user_choice}, 컴퓨터: {computer_choice}")
        result = determine_winner(user_choice, computer_choice)
        print(f"결과: {result}")
        
        play_again = input("다시 하시겠습니까? (y/n): ").strip().lower()
        if play_again != "y":
            print("게임 종료")
            break

if __name__ == "__main__":
    main()

반응형
● LIVE: 2026년 최신 데이터 업데이트 완료

"이번 주 1등 당첨 명당,
지도로 바로 확인하세요!"

전국 1등 배출 데이터를 기반으로 분석한
내 주변 실시간 S등급 명당 리스트

로또 명당 지도 샘플
🔍 우리 동네 숨은 명당 찾는 중...

* 1등 배출 횟수 및 거리를 실시간으로 계산합니다.


관련글 더보기