python - 你如何解决这个while循环?
问题描述
编辑:我有另一个问题,但它不会让我再次发布
代码是这样的:
print('''Which group of queens do you want to compete against?
1. Winners
2. Runner-ups
3. Lip sync assassins
4. Miss Congenialities
5. First Eliminated
6. Returning queens''')
choice = int(input())
while choice > 6:
if choice == 1:
contestants = ["BeBe Zahara Benet", "Tyra Sanchez", "Raja", "Sharon Needles", "Jinkx Monsoon", "Bianca Del Rio", "Violet Chachki", "Bob the Drag Queen", "Sasha Velour", "Aquaria", "Yvie Oddly", "Chad Michaels", "Alaska", "Trixie Mattel", "Trinity the Tuck", "Monét X Change"]
elif choice == 2:
contestants = ["Nina Flowers", "Raven", "Manila Luzon", "Chad Micheals", "Alaska", "Courtney Act", "Ginger Minj", "Kim Chi", "Peppermint", "Eureka", "Brooke Lynn Hytes", "Katya", "Kennedy Davenport", "Monique Heart"]
elif choice == 3:
contestants = ["Akashia", "Jujubee", "Alexis Mateo", "Latrice Royale", "Coco Montrese", "Trinity K. Bonet", "Kennedy Davenport", "Chi Chi DeVayne", "Peppermint", "Kameron Michaels", "Ra'Jah O'Hara", "Raven", "Alaska", "BenDeLaCreme", "Trinity the Tuck"]
elif choice == 4:
contestants = ["Nina Flowers", "Pandora Boxx", "Yara Sofia", "Latrice Royale", "Ivy Winters", "BenDeLaCreme", "Katya", "Cynthia Lee Fontaine", "Valentina", "Monét X Change", "Nina West"]
elif choice == 5:
contestants = ["Victoria Parker", "Shangela", "Venus D-Lite", "Alisa Summers", "Penny Tration", "Kelly Mantle", "Tempest DuJour", "Laila McQueen", "Jaymes Mansfield", "Vanessa Vanjie Mateo", "Soju", "Mimi Imfurst", "Coco Montrese", "Thorgy Thor", "Jasmine Masters"]
elif choice == 6:
contestants = ["Carmen Carrera", "Shangela", "Kenya Michaels", "Trixie Mattel", "Naysha Lopez", "Cynthia Lee Fontaine", "Eureka", "Vanessa Vanjie Mateo", "Alyssa Edwards", "Tatianna", "Morgan McMichaels", "Latrice Royale", "Manila Luzon"]
else:
while choice > 6 or choice < 1:
print("Please choose one of the 6 groups")
choice = int(input())
不起作用的部分是:
else:
while choice > 6 or choice < 1:
print("Please choose one of the 6 groups")
choice = int(input())
循环继续进行,无论我输入什么(除非我输入除整数以外的任何内容,它会显示错误消息)。当我输入 1 到 6 之间的整数时,如何停止这种情况?
解决方案
编辑:正如我所见,您添加了更多代码。您正在检查您的选择是否大于6,然后与小于 6 的值进行比较。您永远不会遇到该while
循环。
无需遍历索引。直接循环列表。
for x in contestants:
print(x)
time.sleep(0.5)
推荐阅读
- angular - 在 Angular 2 中,如何将 Date 转换为 yyyy-MM-ddT00:00:00.000Z 格式?
- python - 如何使用 map 和 lambda 表达式跟踪索引?
- typo3 - 错字3:如何更改介绍包标志的大小
- django - 为什么 objects.create() 静默失败?
- html - 无法在 .hta(Microsoft HTML 应用程序主机)文件上嵌入带有链接的网站
- json - 连接 JSON 文件中的名称和数字字段
- flutter - 我在 Flutter/Dart 异步代码执行方面遇到问题,就像它是如何工作的一样
- python - ModuleNotFoundError:没有名为“__main__.pyrfc”的模块;'__main__' 不是一个包
- maven - 为什么 Gitlab 不能通过 CI 连接到仓库?
- c# - 如何让 WebGL 在这个实现中显示一个虚拟图像?