Practise makes perfect


#1

Hello,can someone please help me with this one,i had changed my code for some millions time,but still it says that i havent defined the function by_three.. maybe i dont see something.. my code for now looks like this
def cube(number):
number = number * number * number
return number

def by_three(number):
if number % 3 == 0:
return ('%s is divisible') % (cube(number))
elif number % 3 != 0:
return ('%s is not divisible') % (number)
else:
return ('by_three is False')


#2

try %d instead of %s

delete that cube function and put

number = number * number * number
return number

part inside by_three function

def by_three(number):
    number = number * number * number
     rn number
     **rest of your code**

#3

still the same..
can i ask what is the differenc of those "s" and "d"?


#4

%s means you must use this for string
%d you must use this for integers
%f for floats

I just modified your code and it works

def by_three(number):
    number = number * number * number
    if number % 3 == 0:
        return ('%d is divisible') % (number)
    elif number % 3 != 0:
        return ('%d is not divisible') % (number)
    else:
        return ('by_three is False')
print by_three(5)

#5

""" def by_three(number):
number = number * number * number
return number
if number % 3 == 0:
return ('%d is divisible') % (cube(number))
else:
return ('by_three is False')
"""
changed my code for shorter wersion,but it in bouth ways says that ""Oops, try again. by_three(1) returned '1 is not divisible' instead of False""
am i understanding something??


#6

yo
remove that return number part
and try again
because you return(prints) your number

and in number % 3 == 0: here it assumes null value for number


#7

def by_three(number):
number = number * number * number
if number % 3 == 0:
return (" %d ") % (number)
else:
return False
print by_three(1)
had gone this far.. but now there is bad situation with number 3.... by_three(3) returned ' 27 ' instead of 27


#8

from where you got this ques I mean at which topic


#9

functions..6. practise makes perfect


#10

which one


#11

Hello
first of all, you supposed to have two functions

One def cube(number) which supposed to return cube of number. You can do calculations in return like return number**3

Second function def by_three(number) must check if given number is divisible by 3. If yes then it use function cube to multiply that number and prints it. If number is not divisible by 3 it returns False.


#12

yeah i got it.. i had to much signs in it,must do everything much more simple..
thatk you for helping me and waisting your time on this