# Saving Functions into Package in Jupyter Notebooks

not sure if I'm phrasing my question correctly but here goes. I've been using Python in a Juptyer Notebook on juptyer hub for one of my class. I've written many useful functions that I want to use to solve problems with. Right now, I have a code block at the beginning of my notebook with all the functions. Like this

import math
from fractions import Fraction

def ln(x):
return math.log(x)
def lg(x):
return math.log(x,2)

#Binomial Distribution
def binom(n,k,p):
#binom(10,3,0.3), 0.266
return math.comb(n,k)*p**k*(1-p)**(n-k)

def WrtFish():
#Test WrtFish(), h,10,3,3 0.266
poptype = input('Is the population haploid or diploid? Enter h or d.')
rawpop = input('How many individuals are in the population?')
if poptype == 'h':
pop = int(rawpop)
elif poptype == 'd':
pop = 2*int(rawpop)
rawgen1 = input('How many individuals in the current generation have the trait?')
rawgen2 = input('How many individuals in the next generation are being inquired about?')
i = int(rawgen1)
j = int(rawgen2)
p = i/pop
return binom(pop,j,p)


It's gotten execessive, and I wanted to know if it's possible for me to make my own package for my own use. My ideal goal is to be able to chuck all of these in a package that I can update and import in new notebooks. e.i. I want to store all these functions in a notebook and be able to call them in a blank notebook where I can work out problems. I'd appreciate insight you could give. Thank you!!!

• Welcome to the Code Review Community. We only review code that is working as expected, there are other sites that will help you debug your code or answer how to questions. Do you want a code review? Please read Where can I get help? and How do I ask a good question?. Jan 8 at 17:02