Maybe a stupid question but I have been working with these https://www.codecademy.com/courses/learn-python-3/articles/python-code-challenges-functions
Quiz 5 asks: Write a function named
remainder() that has two parameters named
num2 . The function should return the remainder of twice
num1 divided by half of
I got the solution as:
def remainder(num1, num2): magic_number = (num1 * 2) % (num2 / 2) return magic_number print(remainder(15,14)) print(remainder(9,6))
Which is correct.
I first tried the following, Ive also searched all over for the answer:
Is it possible to do this:
def remainder(num1, num2): magic_number = (num1 * 2) % (num2 / 2) return magic_number #calculate num1 num1_twice = num1 * 2 return num1_twice #calculate num2 num2_half = num2 / 2 return num2_half #calculate remainder with Modulo between the two variables remainder_mod = num1_twice % num2_half return remainder_mod print(remainder(15,14)) print(remainder(9,6))
Can Modulo be used like this?