상세 컨텐츠

본문 제목

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

시사경제지식

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()

반응형

ai 핫토픽

챗GPT 무료 와 챗GPT 유료 차이점과 GPT-4 무료 사용법

챗GPT 어플, 안드로이드 앱 설치와 사용법, GPT-4o 음성 대화, 무료 사용법

GPT-5와 의료 분야, AI의 역할 재정립

경제 지표 시계열 분석을 통한 정책 제언, 파이썬을 활용한 GDP 성장률 예측과 그 활용법

챗GPT 한국어 설정, 챗GPT 한글 사용법


챗GPT 무료로 사진같은 그림 그리기


관련글 더보기