From fb96ca4b63cbfe5e44e8a338b1c4b0b46a84a627 Mon Sep 17 00:00:00 2001 From: Fred Z Date: Mon, 19 Feb 2018 11:52:06 +0100 Subject: [PATCH] Asking for if statement in try/except bloc --- tryexcept.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tryexcept.py diff --git a/tryexcept.py b/tryexcept.py new file mode 100644 index 0000000..a60732c --- /dev/null +++ b/tryexcept.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Author: freezed 2018-02-19 +Version: 0.1 +Licence: `GNU GPL v3` GNU GPL v3: http://www.gnu.org/licenses/ + +Testing conditions in try/except statement + +https://stackoverflow.com/questions/48864496/adding-if-statement-in-a-try-except-bloc +""" +# ? if user_select_map_id is int(): ? + +DEBUG_MODE = [False, True] + +for status in DEBUG_MODE: + print("DEBUG_MODE: {}".format(status)) + number = input("Type a integer: ") + try: + number = int(number) + except ValueError as except_detail: + if status: + print("ValueError: «{}»".format(except_detail)) + else: + print("«{}» is not an integer".format(number)) + else: + print("Your number {} is an integer".format(number))