Practice Makes Coders Frustrated [SOLVED]


#1

6. Practice Makes Perfect

I'm completely stuck, here's my code (img):


#2

Alright, I have two things to tell you to do for all your posts. First, only do as much as the lesson asks you to do, you do more then the lesson checker will most likely not understand your code and say your wrong when your code technically may be code.

Second, from now on, please post your actual code formatted instead of a screenshot, it bothers people when you don't. :slight_smile:

Now for the actual problem in your code. What's your thinking behind this line?

Number = cube(number)

They told us to only return the cubed function of the number if it is divisible by three.


#3

If I add things that the lesson didn't ask for, it's 'cause I looked around the forum and saw someone do that. I had also seen people screenshot their code and thought that was expected, I'll definitely stop doing both things.

I removed Number = cube(number) and it finally went through.

Thanks


#4

You're welcome, and I understand that people follow examples they see. Heck, I have a few mistakes of my own through that. Also don't copy what you see, because it may not be right always. Do you understand why you have to remove that line? Otherwise I can explain why.


#5

I thought that because we were using def I thought I needed to define (number).
Why was it wrong?

I appreciate you helping out dude.


#6

Your divisibility check is pretty fishy as well. Consider what it'll do for 30 and 31, one should be determined to be divisible by 3, and the other should not. I believe you'll find that they both get the same outcome in your boolean expression as both 30 / 0 and 31 / 0 are non-zero values. You'll have to think a bit harder about the divisible-by-three property, the definition of this property describes how to test for it, use that.


#7

I had completed this exercise before I got an answer, I looked back and here was the code I used:

def cube(number):
    return number**3
    
def by_three(number):
    
    if number % 3 == 0: 
        return cube(number)
    else: 
        return False

Is this alright or still a bit off?


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.