Python Python Basics (2015) Number Game App Squared


i'am not able to determine what to do in the question if somebody can send me his/her code to this solution it would be a great help...
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
def squared(square):
    if square == int():
        return square*square
    elif square == str():
        return len(string)*len(string)

2 Answers

Sathvik Koneru
Sathvik Koneru
6,314 Points

The elif argument doesn't seem to make sense. The len() function gets the length of the string which in the case of a single-digit number would be 1. Moreover, you should be passing square instead of string here, as square is the parameter passed into this method. Instead what you want to do is use the int() method to unpack the string into an integer. For example:

>>>s = "5"
>>> int(s)

Use this approach to convert the string to an int and complete the elif statement.

Matt Hanson
Matt Hanson
Treehouse Moderator 17,002 Points

Hi there. There was another post about this challenge a few minutes ago with a good explanation, here's a link.