import random def roll_dice(): return random.randint(1, 6) def main(): print("Welcome to the Dice Game!") print("I will roll a six-sided die, and you try to guess the number.") while True: # This loop will continue until explicitly broken guess = int(input("Enter your guess (1-6): ")) if guess < 1 or guess > 6: print("Invalid input. Please enter a number between 1 and 6.") continue dice_roll = roll_dice() print("The die rolls... It's", dice_roll) if guess == dice_roll: print("Congratulations! Your guess is correct!") else: print("Sorry, your guess is incorrect. Better luck next time!") play_again = input("Do you want to play again? (yes/no): ") if play_again.lower() != "yes": print("Thanks for playing!") break # Exit the loop if the player doesn't want to play again if __name__ == "__main__": main()