unsupported operand type(s) for ** or pow(): 'str' and 'int' with Python3
Question:
My Python3 code
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)
Why do I got error if I want to take a square of number?
unsupported operand type(s) for ** or pow(): 'str' and 'int'
From command line no problems
>>> 3**2
9
Answers:
input
returns a string; **
requires 2 numbers.
My Python3 code
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)
Why do I got error if I want to take a square of number?
unsupported operand type(s) for ** or pow(): 'str' and 'int'
From command line no problems
>>> 3**2
9
input
returns a string; **
requires 2 numbers.