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
Asked By: MishaVacic

||

Answers:

input returns a string; ** requires 2 numbers.

Answered By: Scott Hunter
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.