code: def binom_test(x, n=None, p=0.5, alternative="two-sided"):
      """
      Perform a test that the probability of success is p.
  
      This is an exact, two-sided test of the null hypothesis
      that the probability of success in a Bernoulli experiment
      is `p`.
  
      Parameters
      ----------
      x : integer or array_like
          the number of successes, or if x has length 2, it is the
          number of successes and the number of failures.
      n : integer
          the number of trials.  This is ignored if x gives both the
          number of successes and failures
      p : float, optional
          The hypothesized probability of success.  0 <= p <= 1. The
          default value is p = 0.5
      alternative : {'two-sided', 'greater', 'less'}, optional
          Indicates the alternative hypothesis. The default value is
          'two-sided'.
  
      Returns
      -------
      p-value : float
          The p-value of the hypothesis test
  
      References
      ----------
      .. [1] https://en.wikipedia.org/wiki/Binomial_test
  
      Examples
      --------
      >>> from scipy import stats
  
      A car manufacturer claims that no more than 10% of their cars are unsafe.
      15 cars are inspected for safety, 3 were found to be unsafe. Test the
      manufacturer's claim:
  
      >>> stats.binom_test(3, n=15, p=0.1, alternative='greater')
      0.18406106910639114
  
      The null hypothesis cannot be rejected at the 5% level of significance
      because the returned p-value is greater than the critical value of 5%.
  
      """
      x = atleast_1d(x).astype(np.integer)
      if len(x) == 2:
          n = x[1] + x[0]
          x = x[0]
      elif len(x) == 1:
          x = x[0]
          if n is None or n < x:
              raise ValueError("n must be >= x")
          n = np.int_(n)
      else:
          raise ValueError("Incorrect length for x.")
  
      if (p > 1.0) or (p < 0.0):
          raise ValueError("p must be in range [0,1]")
  
      if alternative not in ("two-sided", "less", "greater"):
          raise ValueError(
              "alternative not recognized\n"
              "should be 'two-sided', 'less' or 'greater'"
          )
  
      if alternative == "less":
          pval = distributions.binom.cdf(x, n, p)
          return pval
  
      if alternative == "greater":
          pval = distributions.binom.sf(x - 1, n, p)
          return pval
  
      # if alternative was neither 'less' nor 'greater', then it's 'two-sided'
      d = distributions.binom.pmf(x, n, p)
      rerr = 1 + 1e-7
      if x == p * n:
          # special case as shortcut, would also be handled by `else` below
          pval = 1.0
      elif x < p * n:
          i = np.arange(np.ceil(p * n), n + 1)
          y = np.sum(
              distributions.binom.pmf(i, n, p) <= d * rerr, axis=0
          )
          pval = distributions.binom.cdf(
              x, n, p
          ) + distributions.binom.sf(n - y, n, p)
      else:
          i = np.arange(np.floor(p * n) + 1)
          y = np.sum(
              distributions.binom.pmf(i, n, p) <= d * rerr, axis=0
          )
          pval = distributions.binom.cdf(
              y - 1, n, p
          ) + distributions.binom.sf(x - 1, n, p)
  
      return min(1.0, pval)
  
imports: from __future__ import division, print_function, absolute_import
  import math
  import warnings
  from collections import namedtuple
  import numpy
  from numpy import isscalar, r_, log, around, unique, asarray, zeros, arange, sort, amin, amax, any, atleast_1d, sqrt, ceil, floor, array, compress, pi, exp, ravel, count_nonzero, sin, cos, arctan2, hypot
  from scipy._lib.six import string_types
  from scipy import optimize
  from scipy import special
  from .None import statlib
  from .None import stats
  from .stats import find_repeats, _contains_nan
  from .contingency import chi2_contingency
  from .None import distributions
  from ._distn_infrastructure import rv_generic
label_desc: Use image node_id 30 for calling a global function with example usage: binom_test(x, n, p, alternative) and returns: min, pval, pval