import random def get_new_number(): return random.randint(1, 100) def higher_or_lower_game(): print("Welcome to the Higher or Lower game!") current_number = get_new_number() score = 0 while True: print(f"\nCurrent number: {current_number}") next_number = get_new_number() user_guess = input("Will the next number be (h)igher or (l)ower? (q to quit): ").lower() if user_guess == 'q': print(f"Thanks for playing! Your score: {score}") break print(f"Next number: {next_number}") if (user_guess == 'h' and next_number > current_number) or (user_guess == 'l' and next_number < current_number): score += 1 print("Correct! Your score is now:", score) current_number = next_number else: print("Wrong! Game over.") print(f"Your final score: {score}") break if __name__ == "__main__": higher_or_lower_game()