python - Python - ELIF 语句不会继续 WHILE 循环
问题描述
在课堂上,我们从一个基础程序开始,并将继续在它的基础上进行构建。我被卡住了,不知道为什么当程序到达 ELIF 语句时它不会像第一个 IF 语句那样返回到 WHILE 循环的开头
print("Great Scott! Marty we need to go back to the future!")
print("Marty, lets do a checklist!")
engine = None
circuit = None
while (engine !=1 and circuit != 1):
engine = int(input("Engine on or off? Enter 1 for ON or 0 for OFF\n"))
circuit = int(input("Circuit on or off? Enter 1 for ON or 0 for OFF\n"))
if (engine == 0 and circuit == 0):
print("Marty! we have to turn everything on before we can time travel!")
print("Lets check again!")
elif (engine == 1 and circuit == 0):
print("Lets turn on the time cicruit")
print("Lets check again!")
elif (engine == 0 and circuit == 1):
print("Turn on the engine!")
print("Lets check again!")
else:
print("Great! lets start driving")
speed = 0
while speed < 88:
speed = int(input("Whats our current speed?\n"))
if speed < 88:
print("We need to go faster!")
else:
print("Flux Capacitor Fully Charged")
print("Marty, where we're going, we dont need roads!")
解决方案
实际上只是改变and to or
while (engine !=1 or circuit != 1):
推荐阅读
- python - 如何在 Python 中自动将新值添加到字典中
- c++ - 从文件中获取整行
- java - 如何在 Java 中将 int 值分配给 char?
- pytorch - RuntimeError: input.size(-1) 必须等于 input_size。预期 28,得到 0
- javascript - Browserify 不发送数据写入函数
- reactjs - 使用 Axios 时未从渲染返回 setState
- node.js - 带有嵌套模式的 GraphQL 返回 null
- mongodb - MongoDB游标在迭代之前包含检索到的文档?
- python - 在 Tensorflow 中使用 Numpy 数组条件操作掩码
- c++ - 具有递归控制的可变参数模板