【问题标题】:What's wrong with " except Exception as e"“除了 Exception as e”有什么问题
【发布时间】:2021-10-06 16:01:17
【问题描述】:

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

代码如下

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

【问题讨论】:

  • 正确格式化您的问题。如果您的代码甚至不可读,没有人可以帮助您。
  • 你也应该添加一个语言标签。

标签: python exception except


【解决方案1】:

你有错误语法:

您忘记在 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")

【讨论】:

猜你喜欢
  • 2023-01-30
  • 2011-07-04
  • 2015-02-15
  • 2014-03-18
  • 1970-01-01
  • 1970-01-01
  • 2013-01-01
  • 2019-12-01
  • 1970-01-01
相关资源
最近更新 更多