import random def welcome(): """Function with no parameters.""" print("Welcome to the Adventure Game!") print("Your goal is to survive the challenge.\n") def set_name(): global name name = input("Enter your name: ") print(f"Your character's name is set to: {name}") def roll_attack(): """Rolls a dice and stores result in global variable attack.""" global attack attack = random.randint(1, 6) def roll_defense(): """Rolls a dice and stores result in global variable defense.""" global defense defense = random.randint(1, 6) def encounter(): print(f"\nAn goblin appears!") # Call dice functions to update global variables roll_attack() roll_defense() print(f"{name} attacks with strength {attack}") print(f"Goblin defends with strength {defense}") if attack > defense: print(f"You defeated the goblin!") elif attack < defense: print(f"The goblin defeated you...") else: print("It's a draw. You both walk away unharmed.") # ---- Main Program ---- def main(): welcome() set_name() for i in range(5): encounter() main()