首页 > 解决方案 > “除了 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

标签: pythonexceptionexcept

解决方案


你有错误语法:

您忘记在属性中添加括号

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

  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")

推荐阅读