python-3.x - 为什么 Python 不接受 print 在 While 循环之外?
问题描述
#Tristan Ledlie
#CSC1194C1
#10/21/2020
#Initialize variables
first = True
enter = ""
#While the user hasn't ended the program
while (enter != "END"):
#Take input for enter
enter = float(input("Please input a value(Or END to end the program)... "))
#If this is the first loop:
if (first == True):
minimum = enter
first = False
#If enter is lower than the minimum number:
elif (enter < minimum):
minimum = enter
else ():
print(minimum)
i = input("Press Enter to close the window...")
解释器一直说它期望在打印之前缩进。我不知道出了什么问题。对我来说完全是无稽之谈。
解决方案
你在 else 之后缺少一个语句,如果你不想发生任何事情,请使用pass
.
while condition:
# ...your code...
if condition:
# ...your code...
elif condition:
# ...your code...
else:
pass
print(statement)
另外,后面没有括号else
。
推荐阅读
- google-sheets - 如何禁用链接工作表的自动工作表重命名?
- postgresql - 如何包括总计数以及分页和排序?
- python - Python数据框np.select - 超出最大递归深度
- c - 复制指针时 memcpy() 无法按预期工作
- discord.js - 使用命令的机器人读数
- blogger - 更改博主和同标签帖子中搜索结果背景的颜色
- javascript - 反应:尝试从音频元素创建媒体元素源时出现 InvalidStateError
- json - Laravel 在 Json 对象数组中搜索日期大于今天的列
- android - 在 webview 中处理 volley HTML 响应
- python - 比较两个列表之间相同索引处的项目并将最小值附加到第三个列表?