我的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
答案 0 :(得分:6)
input
返回一个字符串; **
需要2个号码。