Reputation: 1
I have been trying to create a double or square function on python where the result is to give the user the biggest number back when doubling or squaring. The problem states:
double(x) returns 2 * x square(x) returns x**2 double_or_square(x) returns the larger number between double(x) and square(x)
My code so far has been:
def double(x):
return (2 * x)
def square(x):
return (x ** 2)
def double_or_square(x):
return max(d, q)
d = double
q = square
I keep getting errors, what did I do wrong?
Upvotes: 0
Views: 202
Reputation: 54698
You weren't CALLING any of these functions. Of course, the only integer where "double" will be larger is 1.
Do it like this:
def double(x):
return 2 * x
def square(x):
return x ** 2
def double_or_square(x):
d = double(x)
q = square(x)
return max(d, q)
print( double_or_square( 2 ) )
print( double_or_square( 9 ) )
Upvotes: 3