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 trialRobert Valencia
Courses Plus Student 3,735 Pointsnot sure what I did here
the squared game is not working for me, though in the workspace it is working
num = "4"
def squared(num):
try:
num = int(num)
except ValueError:
i = len(num)
while i > 0:
print(num)
i -= 1
else:
squared_num = num ** 2
print(squared_num)
squared(num)
3 Answers
Steven Parker
231,236 Points"Working" is not the same thing as "doing what was asked".
While your program does something, it's not what the challenge asked for. Here's a few hints:
- the challenge asks you only to define the function, not call it
- the challenge asks you to return the results, not print them
- you can easily replicate a string using the "
*
" operator
Robert Valencia
Courses Plus Student 3,735 PointsIām still getting an error
def squared(num):
try:
num = int(num)
except ValueError:
i = len(num)
while i > 0:
return(num)
i -= 1
else:
squared_num = num ** 2
return(squared_num)
Robert Valencia
Courses Plus Student 3,735 PointsThank you very much for your guidance Steven, Iām still not sure what I did incorrectly.