Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Number Game App Squared

Plz help

This challenge is similar to an earlier one. Remember, though, I want you to practice! You'll probably want to use try and except on this one. You might have to not use the else block, though.

Write a function named squared that takes a single argument.

If the argument can be converted into an integer, convert it and return the square of the number (num ** 2 or num * num).

If the argument cannot be turned into an integer (maybe it's a string of non-numbers?), return the argument multiplied by its length. Look in the file for examples.

What does it want me to do! I don't understand the question

squared.py

2 Answers

Hey Ayub! The challenge wants you to write a function that takes a single parameter. This parameter can be a string or an integer. If it's an integer, you should return the square of that number (the number multiplied by itself). If it's a string however it wants you to return the string multiplied by the length of the string I.e. "test" * len("test") = "testtesttesttest").

Please write back if you need more help!

Can you please give an example

if they give you something that can be transformed into a number ( like the string "23456" ) then return 23456 * 23456

if they give you somehting that canNOT be transformed into a number (like the string "Pe3tita") then return "Pe3tita" multiplied by len("Pe3tita")