How to insert a loop inside a subroutine?

I have created subroutines for a Hangman / Guess the word game. I want to ask the user if they want to start a new game after finishing the previous one. I’m stuck between line 35 - 55.
Will anyone please share their expertise how I can better write my code or at least, teach me how to insert the while loop (category) inside my subroutine - def Again():

Thanks a ton in advance!

*Repl link:

Line 35

if allLetters:
      print(f"You've won with {lives} left. Well done!")
      break #should ask user to go again

    if lives <=0:
      print(f"You ran out of lives! The answer is {word}")
      break #should ask user to go again
    else:
      print(f"{lives} lives left")

def Again():
  playAgain=input("Do you want to play again? y/n: ").lower()
  if playAgain=="n":
    print("Hope you enjoyed the game!")
    print("Logging out...")
    time.sleep(2)
    os.system("clear")
    exit()
  else:
    os.system("clear")

Line 55 #needs to add a loop below which leads the user to the while loop below (category)

Can you please elaborate a little on what the goal is? What is the while loop supposed to accomplish? What other improvements do you have in mind for your program?
You already have a while loop on lines 56-85 and your program seems to run fine.

3 Likes

Odd. I have been stuck on those lines for so long and it wasnt looping. I appreciate your time in checking my code. Thanks heaps

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.