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 trialCarlos Pinzon
570 Pointserror message on quiz platform by not on workspaces -> can't multiply sequence by non-int of type 'str'
the Squared quiz, I checked it on workspaces and works fines for either strings or numbers.
but on the quiz platform the it gives me this error: can't multiply sequence by non-int of type 'str'
any ideas as of why would it do that?
thanks!!
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
num = "blah"
def squared(num):
try:
convertion = int(num)
return print(num*num)
except ValueError:
return print(len(num)*num)
squared(num)
2 Answers
Paul Harrison
5,533 PointsHey Carlos - Sorry, I got it to work in console but didn't actually test in the site. I got it to work this way through the code challenge:
def squared(num):
try:
return int(num) ** 2
except ValueError:
return len(num) * num
Only difference is using "int(num) ** 2" instead of "int(num) * num" in the try.
Paul Harrison
5,533 PointsYou don't need to return the print(), just return the num*num or len(num)*num. Then when calling the function try print(squared(num)).
This works for me:
def squared(num):
try:
return int(num) * num
except ValueError:
return len(num) * num
num = "hello"
print(squared(num))
Carlos Pinzon
570 Pointshey Paul ! thank you still the quiz still says that the function returns the wrong value. Basically took the last 2 lines as comments and see, but its is the same result. Really dont know what is wrong with the Quiz as in "what does it want?"
nonetheless thank you for your answer man