def samplesize_confint_proportion(proportion, half_length, alpha=0.05, method='normal'):
 q_ = proportion
 if (method == 'normal'):
  n = ((q_ * (1 - q_)) / ((half_length / stats.norm.isf((alpha / 2.0))) ** 2))
 else:
  raise NotImplementedError('only "normal" is available')
 return n

def samplesize_confint_proportion ( proportion , half_length , alpha = 0.05 , method = 'normal' ) : q_ = proportion if ( method == 'normal' ) : n = ( ( q_ * ( 1 - q_ ) ) / ( ( half_length / stats . norm . isf ( ( alpha / 2.0 ) ) ) ** 2 ) ) else : raise NotImplementedError ( 'only "normal" is available' ) return n
find sample size to get desired confidence interval length parameters proportion : float in proportion or quantile half_length : float in desired half length of the confidence interval alpha : float in significance level .