简体   繁体   中英

Is there any function to stop a function if user input is a pre-defined code?

here in #1 i want to make something like if name is code then start developer function but after developers function is finished it may complete the remaining part of the code but I dont want to Or I dont want to print program finished Tell me something without using if name:=code: Then all the remaining code I need to do if name!=code

def start():
    code = '1037'
    source = input('Your Name')
    if source==code:
        Pass #1
    else:
        start_nocode()#a pre defined fun not shown here```
    print('Program Finished')

You can take advantage of return here. It will stop your method right there and nothing below that in that method will be executed

def start():
    code = '1037'
    source = input('Your Name')
    if source==code:
        dev() # Not defined in this code
        return
    else:
        start_nocode()#a pre defined fun not shown here
    print('Program Finished')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM