Im trying to make a countdown timer with the feature to reset/stop/pause/resume. I tried implementing an if/elif/else statement to check for user input letter within the while loop while it continues looping. However, the loop stops running when the conditional statement executes. How do I implement my intended functionality into the code?
code:
 import time
 import datetime
 def timeinput():
  # Inputs for hours, minutes, seconds on timer
  h = input("Enter the time in hours: ")
  m = input("Enter the time in minutes: ")
  s = input("Enter the time in seconds: ")
  countdown(int(h), int(m), int(s))
# Create class that acts as a countdown
 def countdown(h, m, s):
  # Print options for user to do
  print("Press w to reset \nPress s to stop \nPress a to pause \nPress d to resume")
  # Calculate the total number of seconds
  total_seconds = h * 3600 + m * 60 + s
  # While loop that checks if total_seconds reaches zero
  # If not zero, decrement total time by one second
  while total_seconds > 0:
    # Timer represents time left on countdown
    timer = datetime.timedelta(seconds = total_seconds)
    
    # Prints the time left on the timer
    print(timer, end="\r")
    
    # Delays the program one second
    time.sleep(1)
    # Reduces total time by one second
    total_seconds -= 1
    user=input()
    
    if user=="w":
      total_seconds=0
      print("Timer will now reset")
      timeinput()
   print("Bzzzt! The countdown is at zero seconds!")
  timeinput()
result: outcome of code
As shown in the provided image, the loop stops at 20 secs. My intended action here was for the countdown to continue until the user presses the W key, which shall then reset the countdown back to its original set time at initialization.
 
     
    