significance test (claim test), one sample, test the proportion - simpler code in Python We have two sheets with pictures of dogs and dog owners. On one sheet - owners and their dogs are associated correctly. The other sheet shows random associations between owners and dogs.
61 students are asked to guess which sheet shows the real associations between pictures of owners and pictures of dogs. 49 of them guess correctly. If this was a random guess, 50% would guess right. Is this evidence that students are doing better than plain guessing?
H0: p = 0.5
Ha: p > 0.5
I can calculate the z score like this:
https://www.tutorialspoint.com/statistics/one_proportion_z_test.htm
And then in Python I can get the P-value like this:
from scipy import stats
P_value = stats.norm.sf(z_score)

which gives a P-value of 1.08e-06, so H0 is rejected. Students are doing better than guessing.
Is there a one-liner or two-liner code example in either scipy or statsmodels that would give me the P-value more directly? Just input the number of observations, number of successes, and the expected proportion, and get the P-value directly?
In other words, can I avoid memorizing the formula for the z score, and instead just remember some function in either scipy or statsmodels?
EDIT: Which function in scipy or statsmodels gives the z score in this case?
The emphasis here is of a practical nature - given a claim, I want to type in a couple lines in Jupyter and validate / reject it.
 A: Under $H_0: p = 1/2,$ the number correct $X \sim \mathsf{Binom}(n=61, p=0.5).$
The exact one-sided P-value of outcome $X = 49$ is $P(X \ge 49) = 1-P(X\le 48) \approx 0,$
as computed in R.
1- pbinom(48, 61, .5)        # using CDF
[1] 9.849392e-07
sum(dbinom(49:61, 61, .5))   # using PDF
[1] 9.849392e-07

So the null hypothesis is rejected at any reasonable level.
An approximate P-value (2.019866e-06) can be obtained using a normal approximation to
the binomial null distribution. Either directly or by standardizing, and
using a continuity correction.
n = 61;  p = .5
mu = n*p;  mu
[1] 30.5
sg = sqrt(n*p*(1-p));  sg
[1] 3.905125
1 - pnorm(48.5, mu, sg)
[1] 2.019866e-06

z = (48.5- mu)/sg;  z
[1] 4.609328
1 - pnorm(z)
[1] 2.019866e-06

Without a continuity correction, the P-value agrees with your normal
approximation to the P-value.
z = (49- mu)/sg;  z
[1] 4.737365
1 - pnorm(z)
[1] 1.082577e-06 


x = 0:61;  pdf = dbinom(x, 61, .5)
hdr = "BINOM(61,.5) with Normal Aprx"
plot(x, pdf, type="h", lwd=3, col="blue", main=hdr)
 curve(dnorm(x, mu, sg), add=T, lwd=2, col="red")
 abline(h = 0, col="green2")
 abline(v = 48.5, lwd=2, lty="dotted")

