Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:07:48+00:00 2026-06-14T19:07:48+00:00

Just 5 days into Python, learning through Code Academy. I have no knowledge of

  • 0

Just 5 days into Python, learning through Code Academy. I have no knowledge of any other language (very little knowledge of Ruby!).

What am I doing wrong with this code?


Q: Write a function, by_three, that calls a second function, cube,
if a number is evenly divisible by 3 and "False" otherwise. You should
then return the result you get from cube. As for cube, that function
should return the cube of the number passed from by_three. (Cubing a
number is the same as raising it to the third power).

So, for example, by_three should take 9, determine it’s evenly
divisible by 3, and pass it to cube, who returns 729 (the result of
9**3). If by_three gets 4, however, it should return False and leave
it at that.

Lastly, call by_three on 11, 12, and 13 on three separate lines.

ANS:

def by_three(n):
    orig_num = n
    if (isinstance(orig_num, int) and orig_num%3 == 0 ):
        cube(orig_num)
    else:
        print "False"

def cube(orig_num):
    cube = orig_num**3
    print cube
    return

by_three(11)
by_three(12)
by_three(13)

When I run the above code, here is what I get. Why do these values appear in this way?

False
1728
False
==> None
False
False
1728
Oops, try again.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:07:49+00:00Added an answer on June 14, 2026 at 7:07 pm

    I can’t say why you’re seeing odd results. When I copy your code into the interpreter, I see:

    >>> def by_three(n):
    ...     orig_num = n
    ...     if (isinstance(orig_num, int) and orig_num%3 == 0 ):
    ...         cube(orig_num)
    ...     else:
    ...         print "False"
    ... 
    >>> def cube(orig_num):
    ...     cube = orig_num**3
    ...     print cube
    ...     return
    ... 
    >>> by_three(11)
    False
    >>> by_three(12)
    1728
    >>> by_three(13)
    False
    

    I think this problem is a lot simpler than you’re making it, though. It’s hard to tell because the question is rather poorly written, but this would be my answer:

    def by_three(n): return False if n % 3 else cube(n)
    
    def cube(n): return n**3
    
    by_three(11)
    by_three(12)
    by_three(13)
    

    And this is what it looks like in the interpreter:

    >>> def by_three(n): return False if n % 3 else cube(n)
    ... 
    >>> def cube(n): return n**3
    ... 
    >>> by_three(11)
    False
    >>> by_three(12)
    1728
    >>> by_three(13)
    False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning Python a couple of days ago as my first language
So -- here's my jam. I'm SUPER NEW (i.e. days) into Python and have
I'm working just few days with jQuery, so question might be not very interesting.
I am just two days old in using JMeter . I have been asked
I am new to splunk. Just 3 odd days at it. I have been
I just started learning Common Lisp a few days ago, and I'm trying to
I'm a few days into learning Clojure and are having some teething problems, so
Just some days ago I started looking into a unit test framework called check,
I have discovered Kohana just 2 days ago and, after facing a few problems
I just started looking into selenium for automated testing for the past few days

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.