Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
967 B
1
Indexable
Never
import random

def flip_coin():
    """Simulate flipping a coin."""
    return 'Heads' if random.choice([True, False]) else 'Tails'

def main():
    print("Welcome to the Coin Flip Game!")
    print("You can guess 'Heads' or 'Tails'.")
    
    while True:
        guess = input("Enter your guess (Heads/Tails) or 'quit' to exit: ").capitalize()
        
        if guess == 'Quit':
            print("Thanks for playing!")
            break
        elif guess not in ['Heads', 'Tails']:
            print("Invalid input. Please enter 'Heads' or 'Tails'.")
            continue
        
        result = flip_coin()
        print(f"The coin landed on: {result}")
        
        if guess == result:
            print("Congratulations! You guessed correctly!")
        else:
            print("Sorry, you guessed wrong.")
            
        print()  # Print a blank line for better readability

if __name__ == "__main__":
    main()
Leave a Comment