简体   繁体   English

如果用户输入的是预定义的代码,是否有任何 function 来停止 function?

[英]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在#1 中我想做一些类似 if name is code 然后启动开发人员 function 但在开发人员 function 完成后它可能会完成代码的其余部分但我不想或者我不想打印程序完成告诉我一些没有使用 if name:=code: 然后我需要做的所有剩余代码 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.您可以利用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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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