def cube(number):
return number * number * number
def by_three(number):
number=int(raw_input ("enter a number that is divisble by three"))
if number % 3 == 0:
return cube(number)
else:
print "enter a valid number"
by_three()
how do i make sure this loops and asks to enter valid number the get the cube
So currently, you ask for the function to be supplied with an argument of a number, but then promptly overwrite it with the raw_input request. If you ran the function within the same indentation as the else statement then it would run again if the else statement gets run. Just be careful of entering an infinite loop.
ok so i tested it. an ( if number % 3 == 0:) and if i put number(1) % 3 it still print the number or ever number(0) % 3 == 0 it still prints. how no matter if it equal 0 or not it still returns the number. how
Zero divided by anything is zero. Zero times anything is zero. Zero minus zero is zero. Put in the time to search for remainder operator to fill the gaps. It’s easiest to illustrate with pencil and paper using long division of integers.
ok, my last shot at it. this is how I’m looking at it. (if number % 3 == 0: ) let’s say the number 5 the remainder is going to come back 2. now that does not equal 0 but it still returns as if it does. now tell me where I went wrong and write how it is supposed to look Plz.
The rules for zero only apply to zero. 5 % 3 is 2 because when we remove the part that divides correctly, the remainder is 2. Pull out a pencil and some paper and long divide without decimals. Integer division, as it were.
d D q
7 ) 27 | 3
-21 q * d
----
6 D - q * d => R
Quotient 3 Remainder 6, thus 27 % 7 is 6.
Legend
d => divisor
D => Dividend
q => quotient
R => Remainder