From b9e26b9d0cc9e053f3c561b24e8ae8de22ba10e9 Mon Sep 17 00:00:00 2001 From: Thomas Bullock <tom.bullock@utu.fi> Date: Wed, 7 Nov 2018 14:53:44 +0200 Subject: [PATCH] Added power --- test_unnecessarymath.py | 5 +++++ unnecessarymath.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/test_unnecessarymath.py b/test_unnecessarymath.py index c996ff3..31220b2 100644 --- a/test_unnecessarymath.py +++ b/test_unnecessarymath.py @@ -8,3 +8,8 @@ def test_sqrt(): assert um.sqrt(1.) == 1. assert um.sqrt(0.) == 0. assert um.sqrt(4.) == 2. + +def power_test(): + assert um.power(3, 3) == 27 + assert um.power(2, 4) == 16 + assert um.power(5, 3) == 125 \ No newline at end of file diff --git a/unnecessarymath.py b/unnecessarymath.py index 71d4ad6..246be46 100644 --- a/unnecessarymath.py +++ b/unnecessarymath.py @@ -23,3 +23,14 @@ def square(x): 16.0 """ return x * x + +def power(x, y): + """ + Evaluates a number x to the power y + + >>> power(2, 3) + 8 + >>> power(3, 2) + 9 + """ + return x ** y \ No newline at end of file -- GitLab