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

Robert Valencia
PLUS
Robert Valencia
Courses Plus Student 3,735 Points

not sure what I did here

the squared game is not working for me, though in the workspace it is working

squared.py
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
Steven Parker
231,007 Points

:point_right: "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
PLUS
Robert Valencia
Courses Plus Student 3,735 Points

Iā€™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
PLUS
Robert Valencia
Courses Plus Student 3,735 Points

Thank you very much for your guidance Steven, Iā€™m still not sure what I did incorrectly.