"Practice Makes Perfect"


#1


https://www.codecademy.com/courses/python-beginner-c7VZg/1/5?curriculum_id=4f89dab3d788890003000096


def cube(number):
    if cube == cube.upper():
       return "The cube of that number!"
def by_three(number)
    if by_three == number.upper():
    return "False!"


#2

Hi why do you use the method .upper()? its use to uppercase string ..
you can read about it here
http://www.tutorialspoint.com/python/string_upper.htm

the lesson aske you to

1 First, def a function called cube that takes an argument called number. Don't forget the parentheses and the colon!

2 Make that function return the cube of that number (i.e. that number multiplied by itself and multiplied by itself once again)

def cube(number):
     return number ** 3

or

def cube(number):
    return number * number * number

then

3 Define a second function called by_three that takes an argument called number.

def by_three(number):

4 if that number is divisible by 3, by_three should call cube(number) and return its result. Otherwise, by_three should return False.

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

#3
 MY code still doesn't run correctly.  Please advise.

#4

My code still doesn't run correctly. Please advise.


#5

can you post your code?


#6

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


#7

sorry If wasn't clear but it should be like that

def cube(number):
    return number ** 3

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

#8

this is a code that works, i took the liberty of adding my own touch, but the raw code is pretty simple. took me some time do solve this. really wanted to make a raw input for the number, but didn't quite managed it, maybe I'll learn in some other lesson.

def cube(number):
"""Returns the cube of a number."""
cubed = number**3
print "%s squared is %s." % (number,cubed)
return cubed

cube(10)

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


#9

make sure you correct the code with TAB, would do it myself, but don't really know how to do it (post the code in a square like you guys).


#10

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

Why is this code not working .


#11

Hi what error do you get?


#12

File "python", line 3
return number*number*number
^
IndentationError: expected an indented block


#13

Like the error says... IndentationError: expected an indented block so it should be like that

def cube(number):
    return number*number*number

#14

Still not working!! and thanks for responding


#15

Can you post your code and the error you get now?


#16

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

Error:
File "python", line 5
if number % 3 == 0:
^
IndentationError: expected an indented block


#17

sorry

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


#18

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


#19

Actually return is not showing with spaces/indentation for some reason but there is space like you suggested.


#20

here how to format your code