根据用户输入从特定位置重新启动python脚本

根据用户输入从特定位置重新启动python脚本,python,Python,Hello overflow的社区,今天我试图创建一个聊天机器人项目,只是为了了解更多关于python的知识,但我在创建循环时遇到了一个问题,不知道如何解决它,并尝试搜索web和此网站,但没有找到任何东西,下面是我的代码: l_greeting = ["hello", "Hello", "HELLO", "hELLO", "مرحبا"] print ("Welcome to sami's chatting bot") greeting = str(input("Feel free to cha

Hello overflow的社区,今天我试图创建一个聊天机器人项目,只是为了了解更多关于python的知识,但我在创建循环时遇到了一个问题,不知道如何解决它,并尝试搜索web和此网站,但没有找到任何东西,下面是我的代码:

l_greeting = ["hello", "Hello", "HELLO", "hELLO", "مرحبا"]
print ("Welcome to sami's chatting bot")
greeting = str(input("Feel free to chat the bot:  "))
    if greeting in l_greeting:
        print("Hello :D ")
    else:
        print ("I can't understand what you are saying, try again without 
using caps")
        break
我真正想要的是使代码从单词不在我的单词列表中的位置运行,并使脚本在单词之后的位置继续运行。

  • 您应该在while循环中输入
    ,让用户再次输入
    一次又一次
  • 在if块中打印“Hello”之前,请删除continue
  • 也要把裂缝去掉
检查以下更新的代码:

l_greeting = ["hello", "Hello", "HELLO", "hELLO", "مرحبا"]
print ("Welcome to sami's chatting bot")
while True:
    greeting = str(input("Feel free to chat the bot:  "))
    if greeting in l_greeting:
        print("Hello :D ")
    else:
        print ("I can't understand what you are saying, try again without using caps")

可能与您的兴趣相关。谢谢,但如果有人能给我一个关于我的代码的示例,我会更容易理解,因为我不太熟悉Python我不太确定您想知道什么,但一个问题是,如果您到达
continue
,控制流将再次从循环的顶部开始,因此,
print(“Hello”)
永远不会执行。第5行如果在l_greeting中使用问候语:^IndentationError:unexpected indents我为您创建了一个代码片段:,效果很好,请查看。谢谢,我复制了一些错误的内容,但您已经回答了我50%的问题,现在,我如何让脚本从错误发生的地方开始,而不是从乞讨的地方开始,或者它与上面的答案相同?我也这样做了。。。检查示例