【发布时间】:2019-08-02 10:03:33
【问题描述】:
用这个小转换器有点挣扎,我无法让它通过第一个输入,这是反复要求的。有没有更优雅的方法来解决让我脱离循环的 ValueError 问题?
编辑:我还玩弄了 a=1 和 a=0 的位置,当我这样做时,它不再要求我输入,但它只是运行脚本而不要求我提供第二个用户输入。
谢谢各位!
import scipy.stats as st
a=1
while a==1:
try:
choice = input('Press 1 for percentages to Z-Score, 2 for Z-score into percentages, one tailed')
if choice ==1:
percentage = input('Enter value')
print(st.norm.ppf(percentage))
a=0
if choice ==2:
score = input('Enter value')
print(st.norm.cdf(score))
a=0
except ValueError:
print('Invalid Entry')
a=1
【问题讨论】:
标签: python-3.x while-loop scipy normal-distribution valueerror