python - 为什么我的简单程序在运行后没有结束?
问题描述
这是我的小程序:从一组字母中创建所有可能的字符串。
问题:我希望它在获得列表后停止,PyCharm 等待我按下停止按钮。
import random
liste = []
char_list = ['a', 'b', "c", "d"]
while True:
random.shuffle(char_list)
n = ''.join(char_list)
if n in liste:
continue
elif n not in liste:
print(''.join(char_list))
liste.append(n)
else:
break
为什么这个程序在给出列表后没有停止?
解决方案
它永远不会因为你的条件而停止。
# If n is in liste...
if n in liste:
continue
# Otherwise, if n not in liste...
elif n not in liste:
print(''.join(char_list))
liste.append(n)
# Will never happens, because either n is or is not in liste...
else:
break
推荐阅读
- typescript - 扩展外部接口
- azure - 无法删除 Azure Active Directory 自定义域
- file-io - SAS Infile 语句分隔符
- azure-devops - Azure DevOps PublishPipelineArtifact 在失败时未运行
- java - Springboot线程数不断增加
- javascript - Selectpicker(引导选择)不起作用,显示禁用的菜单?
- python - 循环显示正确答案为不正确
- php - 类型提示和多个接口
- python - pandas 自动迭代行并连接结果?
- javascript - 事件侦听器即使在 chrome 上也不起作用?