From 5924cea46f62dcfad81e62a8375bd79be48f0067 Mon Sep 17 00:00:00 2001 From: damoklov <37833994+damoklov@users.noreply.github.com> Date: Sat, 6 Oct 2018 23:31:37 +0300 Subject: [PATCH] Added useful Python file for checking input data You can experiment with this file, add smth to it and use in your modules. Example of usage: >>>123 >>>Correct! >>>fsda12 >>>ValueError >>> >>>Enter something --- code/try_except.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 code/try_except.py diff --git a/code/try_except.py b/code/try_except.py new file mode 100644 index 0000000..0133c7f --- /dev/null +++ b/code/try_except.py @@ -0,0 +1,14 @@ +while True: + line = input() + + if line: + try: + a = int(line) + print("Correct!") + exit(0) + except ValueError as vr: + print("Value Error:",vr) + continue + else: + print("Enter something") + continue