[英]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.