Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions 9 math/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Power function

# What it does
Given a base and power using recursion, calculates the result by multiplying the base by the base to the power of power minus one.

# How to use
Run the program
Type in your base
Type in your power
16 changes: 16 additions & 0 deletions 16 math/power.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def ofun_power(base:int, power:int):
# Base case once power reaches 0 function will stop
if power == 0:
return 1

if power > 0:
return base * ofun_power(base, power - 1)
# This will be used if the power if negative resulting in a fraction
elif power < 0:
return (1/base) * ofun_power(base, power + 1)


user_base = input("Input base: ")
user_power = input("Input power: ")

resulted_power = ofun_power(user_base, user_power)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.