 # [SOLVED] Cubic Minefield (Simplified help please)

There have been a lot of other posts which talk about it, but I still don’t understand how to do it. Could someone please help?

This is my code:

``````# 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

# This function returns the number to the exponent power.
def power(number, exponent):
total = 1
# Complete the function.
while exponent > 1:
total *= number
exponent -= 0

# Don't change the following code
# You can find coefficients for the equation on the tower
tower = hero.findFriends()
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

``````

Two things I noticed.

``````    while exponent > 1:  # not quite correct
total *= number
exponent -= 0  #subtracting 0 which creates an infinite loop
``````

when you say, “not quite correct”, what about it isn’t correct? Also, I tried to copy the first function, but i just don’t get how it works.

I’ll explain the function in more detail. In your main code, you will call the function and it will take arguments (some type of value) to run through the function. So if the code said `mult(5,2)` the variables in those positions take those values.
`number = 5`
`times = 2`

``````def mult(number, times):
total = 0 #initial value to start
while times > 0: # keep going until times value (2 to start) is not greater than zero (equals zero)
total += number # add number value (5) to the total every time (total(0) + number(5) = 5 after first loop)
times -= 1 # subtract 1 from times value (2-1 = 1 after first loop)

``````

Below are the values that the variable will have after each loop. Watch how the total increases while the times decreases every loop.
total = 0
1st loop
total = 5 and times = 1
2nd loop
total = 10 and times = 0
times not greater than 0 - stop loop
total = 10

To answer what isn’t correct, what number is in the while loop in the mult() ` while times > ??:`? And make sure you subtract by 1 instead of zero to decrease the exponent value.

This is my new code. My character continues to move up instead of moving in the right direction. I am sorry that I keep getting this wrong.

``````# 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

# This function returns the number to the exponent power.
def power(number, exponent):
total = 0
# Complete the function.
while exponent > 0:
total += number
exponent -= 1

# Don't change the following code
# You can find coefficients for the equation on the tower
tower = hero.findFriends()
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

``````

You corrected the two lines that were wrong, but then changed the one line that was correct in the while loop for exponent. Switch that back and you should be good. To get multiples you add the number to get powers you ??? the number?

Thank you so much! I figured it out!