본문 바로가기
코딩

마텔에서 만든 Magic 8 Ball 장난감을 파이썬으로 구현해보자.

by 노마드랩스 2023. 2. 17.
728x90
반응형

이 코드는 클래식 Magic 8 Ball 장난감의 디지털 버전을 만드는 데 사용할 수 있습니다. 사용자는 질문을 입력할 수 있으며 프로그램은 미리 결정된 여러 답변 중 하나를 무작위로 생성합니다.

import random

# List of pre-determined answers
answers = [
    "It is certain.",
    "It is decidedly so.",
    "Without a doubt.",
    "Yes - definitely.",
    "You may rely on it.",
    "As I see it, yes.",
    "Most likely.",
    "Outlook good.",
    "Yes.",
    "Signs point to yes.",
    "Reply hazy, try again.",
    "Ask again later.",
    "Better not tell you now.",
    "Cannot predict now.",
    "Concentrate and ask again.",
    "Don't count on it.",
    "My reply is no.",
    "My sources say no.",
    "Outlook not so good.",
    "Very doubtful."
]

# Welcome message
print("Welcome to the Magic 8 Ball Game!")

# Ask for user's question
question = input("What is your question? ")

# Generate a random answer
answer = random.choice(answers)

# Print the answer
print("\nThe Magic 8 Ball says:")
print("\n" + answer + "\n")

 

감사합니다. 열심히 할게요.

728x90
반응형

댓글