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

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")