**或pow()的不支持的操作数类型:Python3的'str'和'int'

Mis*_*cic -1 python

我的Python3代码

def ask():

    while True:
        try:
            n = input('Input an integer: ')
        except:
            print ('An error occurred! Please try again!')
            continue
        else:
            break


    print ('Thank you, you number squared is: ', n**2)
Run Code Online (Sandbox Code Playgroud)

如果我想取一个数字的正方形,为什么会出错?

unsupported operand type(s) for ** or pow(): 'str' and 'int' 
Run Code Online (Sandbox Code Playgroud)

从命令行没问题

>>> 3**2
9
Run Code Online (Sandbox Code Playgroud)

Sco*_*ter 6

input返回一个字符串; **需要2个数字.