“例外情况除外为e”有什么不对

2024-10-01 09:28:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码出现以下错误。 有人能帮我吗

代码如下

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

Tags: 代码antrueinputdefas错误exception
1条回答
网友
1楼 · 发布于 2024-10-01 09:28:09

您有错误语法:

您忘记在属性中添加括号

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

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

相关问题 更多 >