简体   繁体   English

如何在不使用库和模块的情况下退出 python 程序

[英]How to exit from a python program without using libraries and modules

I have to check if the input year is aa valid 4 digit no.我必须检查输入年份是否为有效的 4 位数字。 Which isn't a float value or has more than 4 characters.这不是浮点值或超过 4 个字符。 The input is from a file dictionary type.输入来自文件字典类型。

If not I want to exit the program and don't want to continue with the steps and functions after.如果不是,我想退出程序并且不想继续执行之后的步骤和功能。

But the only challenge is I'm trying to do it without the use of libraries like sys etc. Is this possible in Python?但唯一的挑战是我试图在不使用 sys 等库的情况下做到这一点。这在 Python 中是否可能?

try to use:尝试使用:

exit("some message")

it is a built in function它是内置 function

You can check if the input is 4 digits or not by using input<10000 and input>999.您可以使用 input<10000 和 input>999 检查输入是否为 4 位。 You can check if the input is a float or not by using the type keyword.您可以使用 type 关键字检查输入是否为浮点数。 So, your program that you described would look something like this:因此,您描述的程序将如下所示:

if x>999 and x<10000:
  if type(x) != float:
    print("Valid")
  else:
    print("Invalid")
else:
  print("Invalid")

Hope this helps!希望这可以帮助!

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

相关问题 不使用任何库或模块的 Python 随机函数 - Python Random Function without using ANY libraries or modules Python:如何在用户输入3个无效值后结束程序,并防止以下功能在不使用系统退出/中断的情况下运行? - Python: How to end a program after user inputs 3 invalid values and prevent following functions from running without using system exit/break? 如何在没有错误语句的情况下退出 python 程序? - How do you exit a python program without the error statement? 如何在不结束整个程序的情况下退出 function? (Python) - How can I exit a function without ending the whole program? (Python) 在 Python 3 中,使用 Pytest,我们如何测试退出代码:python 程序的退出代码:exit(1) 和 exit(0)? - In Python 3, using Pytest, how do we test for exit code : exit(1) and exit(0) for a python program? 如何在没有回溯的情况下退出 Python? - How to exit from Python without traceback? 如何使用Ctrl-C使用MacFSEvents从Python程序退出 - How to exit from a Python program using MacFSEvents using Ctrl-C 如何从Python 3退出程序(不是python脚本)? - How can I exit a program (not python script) from Python 3? Python中使用外部模块和库的方法有哪些? - What are ways of using external modules and libraries in Python? 不关闭Tkinter窗口退出python程序 - exit python program without close Tkinter window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM