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

时间:2017-06-07 11:34:12

标签: 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)

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

unsupported operand type(s) for ** or pow(): 'str' and 'int' 

从命令行没有问题

>>> 3**2
9

1 个答案:

答案 0 :(得分:6)

input返回一个字符串; **需要2个号码。