-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4387aa5
commit 6ae724c
Showing
1 changed file
with
13 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
def power(base, exponent): | ||
def positive_power(base, exponent): | ||
result = 1 | ||
counter = exponent | ||
print(str(base) + "^" + str(exponent) ) | ||
while counter > 0: | ||
#print( "result=" + str(result) + 'counter=' + str(counter) ) | ||
result = result * base | ||
counter = counter - 1 | ||
#print( "result=" + str(result) + 'counter=' + str(counter) ) | ||
return result | ||
|
||
print( power(2, 8) ) | ||
def power(base, exponent): | ||
if exponent < 0: | ||
return 1/positive_power(base, -exponent) | ||
else: | ||
return positive_power(base, exponent) | ||
|
||
print( power(2, 8) ) | ||
print( power(2, 0) ) | ||
print( power(2, -2) ) |