Raw_input() within defined square() function


#1




I started exploring beyond what was asked and I am wondering why I am receiving an error. Rather than just square 10 to = 100, I decided to combine something I learned previously and use raw_input() within the defined square(n) function to enter in 10 and get 100.

Traceback (most recent call last):
File "python", line 9, in
File "python", line 3, in square
TypeError: unsupported operand type(s) for ** or pow(): 'unicode' and 'int'


def square(n):
    """Returns the square of a number."""
    squared = n**2
    print "%d squared is %d." % (n, squared)
    return squared
    
# Call the square function on line 9! Make sure to
# include the number 10 between the parentheses.
square(raw_input("Enter number"))


#2

Hi, @ajc.shop ,

The raw_input function returns a string. Convert that string to an int and pass the result to the square function.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.