Introduction to Python Resources

Begin your free Python journey now,
at your own pace

check

Syntax: Exponents

check

Raise one number to any power with the Python exponentiation operator.


Exponents in Python

The next math operator to learn about is the exponentiation (**) operator. As you can probably guess, the exponentiation (**) operator is used to raise one numeric value to the power of another. Typical syntax usage for the addition operator are as follows:

  1. What raising one numeric value to the power of another:

      power = 5 ** 3
    
  2. When using one variable to raise one numeric value to the power of another:

      base = 7
      power = base ** 5
    
  3. When using two variables to raise one numeric value to the power of another:

      base = 5
      exponent = 5
      power = base ** exponent
    

Practice: Float Exponentiation

Based on the above information, please complete the following steps:

  1. Define a variable named same_side_length, and assign it 2.1.
  2. Define a variable named opposite_side_length, and assign it 2.8.
  3. Define a variable named hypotenuse_length and, using operators (including exponentiation) and the variables above, assign it the length of the hypotenuse of the right-triangle above.
  4. Print the value contained in the hypotenuse_length variable.
    • Note: if it's been a while since you calculated the hypotenuse of a right triangle, check out the formula here.
HINT*: Click here for a hint
*Hints are best viewed after completing a task, or after spending some time and effort attempting it. In cases where a hint contains example output, it is important to understand why it is correct, as there may be many correct outputs.

You should see the length of the hypotenuse:

> 3.5

Note: the square-root of a number is equivalent to raising the number to the power of 0.5.

SOLUTION*: Click here for an example solution
*Example solutions are best viewed after completing a task and understanding the outcome. In most cases, there are multiple ways to complete a task, and the example solution is only one example.
same_side_length = 2.1
opposite_side_length = 2.8
hypotenuse_length = (same_side_length ** 2.0 + opposite_side_length ** 2.0) ** 0.5
print(hypotenuse_length)

When you have completed the above, you are ready to move on to the next exercise!