Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Number Game App Squared

Thananjaya Chakravarthy
Thananjaya Chakravarthy
4,672 Points

how to return the argument if it is a string?

on checking in my work space, I could able to get the output if the argument is numbers. but , I could not if the argument is string.

kindly, help me out!!

squared.py
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
def squared(num):
    try:
        num1=num*num
        return num1
    except ValueError:
        num2=4*"num"
        return num2

1 Answer

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,822 Points

Hi, Thananjaya Chakravarthy !

You can use "*" with strings.

for example:

 "num" * 2 # it would return "numnum"

So challenge wants you to find length of a given string (which would be an integer) and then multiply given string by that length.

Does it help?