“except Exception as e”有什么问题

问题描述

我的代码出现以下错误。 谁能帮帮我。

代码如下

def askforinteger():
    while True:
        try:
            a = int(input("enter an integer")
        except Exception as e :
            print("there is a error of",e)
        else:
            print("person has entered correct input")
            break
        finally:
            print("clsoe this issue")

错误如下

  File "<ipython-input-5-234fd49c196d>",line 5
    except Exception as e :
    ^
SyntaxError: invalid Syntax

解决方法

你有语法错误:

您忘记在a属性中添加括号

希望这能解决它 试试这个:

  def askforinteger(): 
        while True: 
            try: 
                a = int(input("Enter a number: "))
                print("person has entered correct input") 
            except Exception as e : 
                print("there is a error of",e)     
                break 
            finally: 
                        print("clsoe this issue")