如何尽可能少的代码解决循环和条件语句问题

2024-04-26 11:02:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试允许我的列表检查用户是否拒绝请求, 如果是,它将激活我的if块,允许我邀请另一位客人代替他们。 每次我输入no,而不是激活if块继续打印,我哪里出错了?或者我缺少什么元素?你知道吗

guestllist = ["me","batman","joker","wonder woman","peter rabbit"]
normal = guestllist
guestllist.reverse()

while len(normal):
    # print("welome to the party "  + guestllist.pop())
    result = input("can you come " + guestllist.pop() + "?")
    if result == "no":
        print(result + " cannot make it")
        input("our new guest shall be ")

Tags: no元素列表inputif检查用户resultpop
1条回答
网友
1楼 · 发布于 2024-04-26 11:02:10
guestllist = ["me","batman","joker","wonder woman","peter rabbit"]
guestllist.reverse()
while len(guestllist):
    result = input("can you come " + guestllist.pop() + "?")
    if result == "no":
        print(result + " cannot make it")
        input("our new guest shall be ")

相关问题 更多 >