Cubic Minefield (its me again)

Wow, I sure have a bunch of questions anyway here 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.
    while exponent > 0:
        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
1 Like

I understand how to make a function now but should I put a function inside a function

1 Like

also another level “tiresome gcd” I can’t figure out what function I need to make

1 Like

actually, that didnt work… I least I think it didn’t here is my code now

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 > 0:
        print('begin iteration: total=' + str (total) + 'exponent='+str(exponent))
        total = total
        exponent -= 1
        print('end iteration total =' + str (total) + 'exponenet='+str(exponent))
    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
1 Like

Type Ctrl+Shif+I to open Debug in Browser
Click on Console
If you type as shown above the result will be similar to:

begin iteration: total=1; exponent=3 
end iteration: total=10; exponent=2 
begin iteration: total=10; exponent=2 
end iteration: total=100; exponent=1 
begin iteration: total=100; exponent=1 
end iteration total=1000; exponent=0

the total is 1000 = 101010

and your code returns this:

begin iteration: total=1exponent=3 
end iteration total =1exponenet=2 
begin iteration: total=1exponent=2 
end iteration total =1exponenet=1 
begin iteration: total=1exponent=1 
end iteration total =1exponenet=0

the total is 1
Congratulations @Luke10 - for the first time you don’t like every post!

1 Like

Umm thanks! :open_mouth::no_mouth::astonished:

1 Like

I sorry if you think this is obvious and I don’t but, what do i do whit the total?

Your first code was just missing one minor change. The key to this level is knowing how exponents work. Post below give some more details.