python - 循环顺序问题
问题描述
我写了这个简单的代码:
alpha=float(input('For the MC Test for the mean define alpha (0.10 and 0.05 only available at the moment): '))
if alpha!=0.05 or alpha!=0.10:
while True:
print('Please insert a value equal to 0.05 or 0.10')
alpha=float(input('For the MC Test for the mean define alpha (0.10 and 0.05 only available at the moment): ')
else:
print('MC test will control the FWER at exactly {}% (balanced test)'.format(alpha))
然而,它正在创建一个循环,即使我输入 0.05,它也会再次要求插入 alpha。我会很感激你的意见。谢谢。
解决方案
只需重新排列循环:
while True:
if alpha not in [0.05,0.1]:
print('Please insert a value equal to 0.05 or 0.10')
alpha=float(input('For the MC Test for the mean define alpha (0.10 and 0.05 only available at the moment): '))
else:
print('MC test will control the FWER at exactly {}% (balanced test)'.format(alpha))
break
推荐阅读
- java - java将平面数组结构转换为分层结构
- javascript - JavaScript 标签数量
- c++ - 命名空间函数的多重定义
- php - 如何循环遍历数组和字符串
- javascript - 单击reactjs在数组中添加和删除项目
- excel - Excel 公式在我写一个特定单词后在同一个单元格中写一个单词
- python - 插入数据库Django时出错
- ios - 优先于avfoundation播放器节点的背景音乐(iTunes)
- cordova - 升级到 xcode 9 后,cordova 应用程序将无法构建,错误 70,需要具有推送通知功能的配置文件
- php - 在复杂的 PHP 数组中搜索值