Entering my own code to explore a topic in the tutorial


#1
  1. Exponentiation
    I want to try some other variations on exponents in my little code snippet, but after I press "Save and Submit Code", my only choice is to move on to the next lesson. Can I add lines, change lines or delete something and submit it again?

Thanks


#2

Yes you can play with and practice your code. Look for the [x] on the right side of the footer. That will restore the editor.

Bonus code to play with:

def pow(a, x):
    return a ** x

print pow(11, 2)    # 121

print [pow(3, x) for x in range(11)]

# [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049]

It should be noted that Python has a built in function, pow() that the one above just overwrote. It functions the exact same way.

def exp(x, a):
    return x ** a

print exp(2, 11)    # 2048

print [exp(x, 3) for x in range(11)]

# [0, 1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]

I've actually got these two backwards. The bottom one is the power function (constant exponent) and the top one is the exponential function (constant base).


#3

Thanks. Exactly what I needed. Thanks too for the snippet!
Sean


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.