在python中实现if语句后如何继续

在python中实现if语句后如何继续,python,Python,当程序实现任何if语句时,程序停止。实现if语句后如何保持其运行 def main(): print("Hello i'm your new virtual messenger:") inside = input(); if inside == "Hello" or "Hi" or "Hey" or "Yo": print("hello !") if inside == "Whats's your name": print("My

当程序实现任何if语句时,程序停止。实现if语句后如何保持其运行

def main():
    print("Hello i'm your new virtual messenger:")
    inside = input();
    if inside == "Hello" or "Hi" or "Hey" or "Yo":
        print("hello !")
    if inside == "Whats's your name":
        print("My name is Raito")
    if inside == "Who programmed you" or "Who made you" or "Who've made you":
        print("it's you LOL, because i think no one will use this")
    if inside =="What can you do":
        print("Right now nothing special, died waiting to be updated")
    else:
        print("I Don't know how to answer your question, i told you, im waiting to be updated")

if __name__=='__main__':
    main()

可能您正在寻找while循环,因此您需要如下内容:

def main():
    print("Hello I'm your new virtual messenger:")
    while True:
        inside = input();
        if inside in ["Hello","Hi","Hey","Yo"]:
            print("hello !")
        elif inside == "Whats's your name":
            print("My name is Raito")
        elif inside in ["Who programmed you","Who made you","Who've made you"]:
            print("it's you LOL, because I think no one will use this")
        elif inside == "What can you do":
            print("Right now nothing special, died waiting to be updated")
        else:
            print("I Don't know how to answer your question, I told you, I'm waiting to be updated")

if __name__ == '__main__':
    main()
elif inside == "Exit":
    break 
使用此代码,您将永远循环。 如果您想在某个时刻退出循环,例如,如果您从输入中读取“exit”,则可以使用关键字break(它允许您在while循环之后继续代码),如下所示:

def main():
    print("Hello I'm your new virtual messenger:")
    while True:
        inside = input();
        if inside in ["Hello","Hi","Hey","Yo"]:
            print("hello !")
        elif inside == "Whats's your name":
            print("My name is Raito")
        elif inside in ["Who programmed you","Who made you","Who've made you"]:
            print("it's you LOL, because I think no one will use this")
        elif inside == "What can you do":
            print("Right now nothing special, died waiting to be updated")
        else:
            print("I Don't know how to answer your question, I told you, I'm waiting to be updated")

if __name__ == '__main__':
    main()
elif inside == "Exit":
    break 

这几行代码应该与“if”和“else”之间的其他代码“elif”相同。

您似乎需要一个循环。无论您使用的是什么教程,请继续阅读。
如果inside==“Hello”或“Hi”或“Hey”或“Yo”是错误的。使用
if-inside-in(“Hello”、“Hi”、“Hey”、“Yo”)
如果我正确解释了您的代码,您只需要添加一个循环来解决这个问题,以及@Ayxan的correction@AbhishekPatel谢谢,我会尝试解决这个问题,但我需要使用for或while循环?您可以使用其中的任何一个,因为您需要它一直运行直到用户退出,你可以使它成为一个无限循环。我建议使用教程来帮助您编写这样的程序,以帮助您更好地理解代码