Python Forum
Exit function from nested function based on user input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exit function from nested function based on user input
#1
Hello,

Currently making a chat bot that helps with adding some items to a database. I want a user to be able to start adding something to a database but be able to cancel at anytime.

Here's my current code:
def foo():
    def check(m):
        if m == "stop":
            return

    msg = input("Type a msg: ")
    check(msg)

    msg2 = input("Type another message: ")
    check(msg2)

    msg3 = input("Type a third message: ")

foo()
My thought process was to take the message and run it through a check that would exit out of the process however my check only exists out of the check() function and not the parent foo() function.

I found this thread which is a similar question to mine however I'm not sure exactly how to go about implementing that if it's the same solution.
Reply


Messages In This Thread
Exit function from nested function based on user input - by Turtle - Oct-05-2021, 08:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to revert back to a previous line from user input Sharkenn64u 2 832 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  Input function oldschool 1 678 Sep-14-2024, 01:02 PM
Last Post: deanhystad
  User input with while loops chizzy101010 2 4,866 Aug-25-2024, 06:00 PM
Last Post: chizzy101010
  difference between forms of input a list to function akbarza 6 2,328 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  The function of double underscore back and front in a class function name? Pedroski55 9 2,376 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  nested function return MHGhonaim 2 1,545 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 2,448 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 1,809 Apr-08-2023, 05:40 PM
Last Post: MCL169
  function return boolean based on GPIO pin reading caslor 2 2,048 Feb-04-2023, 12:30 PM
Last Post: caslor
  user input values into list of lists tauros73 3 1,939 Dec-29-2022, 05:54 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020