Solution for Number Guessing (debug)
One important thing is to remember that you can create a toggle by just calling not on a boolean variable every time you'd like to flip the switch.
The other one is that flipping the switch (pressing d) and printing the current value because debug mode is on, are two separate operations that are not directly related and so they can be implemented separately.
examples/loops/number_debug.py
import random hidden = random.randrange(1, 201) debug = False while True: if debug: print("Debug: ", hidden) user_input = input("Please enter your guess [x|s|d]: ") print(user_input) if user_input == 'x': print("Sad to see you leaving early") exit() if user_input == 's': print("The hidden value is ", hidden) continue if user_input == 'd': debug = not debug continue guess = int(user_input) if guess == hidden: print("Hit!") break if guess < hidden: print("Your guess is too low") else: print("Your guess is too high")