It is not a code problem just a math issue I have no clue what this level really wants me to do.
# This function returns the number to the exponent power.
def power(number, exponent):
total = 1
# Complete the function. It must return the cube of the base
return total
I have the SAME PROBLEM GETTING PAST THIS LEVEL!
This is my code
def mult(number, times):
total = 0
while times > 0:
total += number
times -= 1
return total
# This function returns the number to the exponent power.
def power(number, exponent):
total = 1
# Complete the function.
times -= 1
return total
# Don't change the following code
# You can find coefficients for the equation on the tower
tower = hero.findFriends()[0]
a = tower.a
b = tower.b
c = tower.c
d = tower.d
x = hero.pos.x
while True:
# To find the path use a cubic equation
y = a * power(x, 3) + b * power(x, 2) + c * power(x, 1) + d * power(x, 0)
hero.moveXY(x, y)
x = x + 5
The power() is missing some parts. Take a closer look at the mult() function above. You will want to mimic a lot of the setup, with a minor modification to some words and the math symbol.
To get multiplication you add one number as many times of the other. 5 x 4 = 20
5 + 5 + 5 + 5 = 20
To get exponential power, you don’t add one number by the times of the other, but something else: 2 ^ 4 = 16
This function returns the number multiplied by the times
def mult(number, times):
total = 0
while times > 0:
total += number
times -= 1
return total
This function returns the number to the exponent power.
def power(number, exponent):
total = 1
# Complete the function.
while exponent > 1:
total += number
exponent -= 1
return total
Don’t change the following code
You can find coefficients for the equation on the tower
tower = hero.findFriends()[0]
a = tower.a
b = tower.b
c = tower.c
d = tower.d
x = hero.pos.x
while True:
# To find the path use a cubic equation
y = a * power(x, 3) + b * power(x, 2) + c * power(x, 1) + d * power(x, 0)
hero.moveXY(x, y)
x = x + 5
# Walk through the minefield
# This function returns the number multiplied by the times
def mult(number, times):
total = 0
while times > 0:
total += number
times -= 1
return total
# This function returns the number to the exponent power.
def power(number, exponent):
total = 1
# Complete the function.
while hero.time > 1:
total += number
times -= 2
return total
# Don't change the following code
# You can find coefficients for the equation on the tower
tower = hero.findFriends()[0]
a = tower.a
b = tower.b
c = tower.c
d = tower.d
x = hero.pos.x
while True:
# To find the path use a cubic equation
y = a * power(x, 3) + b * power(x, 2) + c * power(x, 1) + d * power(x, 0)
hero.moveXY(x, y)
x = x + 5
Look at the top bit of code as a guide. This level doesn’t need anything to do with hero.time!
while hero.time > 1:
total += number
Think about what the mathematical function is. For ‘times’, if you say 3 times y you actually mean y + y + y. For the third ‘exponential’ of y you want y x y x y. What function do you need to put in?
times -= 2
This should be the same as the one in the top bit of code.