untitled-pastecode_io.txt

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.4 kB
2
Indexable
Never
import random

# רשימת שאלות ותשובות
questions = [
    {"question": "What is the capital of France?", "answers": ["Paris", "London", "Berlin", "Madrid"], "correct": 0},
    {"question": "What is 2 + 2?", "answers": ["3", "4", "5", "6"], "correct": 1},
    {"question": "Who wrote 'Hamlet'?", "answers": ["Charles Dickens", "William Shakespeare", "Mark Twain", "Jane Austen"], "correct": 1}
]

# פונקציה להצגת השאלה והתשובות
def ask_question(q):
    print(f"Question: {q['question']}")
    for i, ans in enumerate(q["answers"]):
        print(f"{i + 1}. {ans}")
    return int(input("Choose the number of your answer: ")) - 1

# פונקציה להרצת המשחק
def play_game():
    money = 1000000
    num_questions = len(questions)
    for i in range(num_questions):
        q = questions[i]
        print(f"\nYou currently have ${money}.")
        player_answer = ask_question(q)
        
        if player_answer == q["correct"]:
            print("Correct! You move on to the next question.")
        else:
            print(f"Wrong! The correct answer was {q['answers'][q['correct']]}.")
            money /= 2  # מאבדים חצי מהכסף
            print(f"You now have ${money}.")
            if money == 0:
                print("You lost all your money! Game over.")
                break
    print(f"Game over! You walk away with ${money}.")

# התחלת המשחק
play_game()
Leave a Comment