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
  difference between forms of input a list to function akbarza 6 1,100 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  The function of double underscore back and front in a class function name? Pedroski55 9 753 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  nested function return MHGhonaim 2 641 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,101 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 946 Apr-08-2023, 05:40 PM
Last Post: MCL169
  function return boolean based on GPIO pin reading caslor 2 1,208 Feb-04-2023, 12:30 PM
Last Post: caslor
  user input values into list of lists tauros73 3 1,093 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,132 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,132 Dec-11-2022, 07:39 PM
Last Post: snippsat
  python difference between sys.exit and exit() mg24 1 1,875 Nov-12-2022, 01:37 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