Emma
Emma

Reputation: 49

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

I have to check if the input year is a a valid 4 digit no. Which isn't a float value or has more than 4 characters. 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?

Upvotes: 0

Views: 141

Answers (2)

usher
usher

Reputation: 86

try to use:

exit("some message")

it is a built in function

Upvotes: 1

arthurkwu
arthurkwu

Reputation: 1

You can check if the input is 4 digits or not by using input<10000 and input>999. You can check if the input is a float or not by using the type keyword. 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!

Upvotes: 0

Related Questions