在while-true循环中输入提示

时间:2018-05-23 22:50:09

标签: python python-3.x while-loop

我想创建一个提示输入的程序,并根据此输入提供定制的回复。

代码是,它完美地工作,除了它根本不循环。 (在CMD或Powershell中运行脚本后,它终止并终止。)

我希望程序在每次运行后返回到输入提示符。我想我需要返回函数,但我不知道给出什么样的参数。

此外,ValueError参数有点无意义,存在问题。

Name = input ("What is your name ? ").strip().lower()

while True:

    try:
        if Name in ("A"):
            print("message for A")
            break       
        else:
            if Name in ("N"):
                print("message for N")
                break
    except ValueError:
        print ("Sorry, my only purpose is to talk to N and A")

    else:
        print("dammit")
        break

0 个答案:

没有答案