微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

“except Exception as e”有什么问题

如何解决“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")

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。