python中while循环

 

1、

>>> a = {}
>>> while a != "quit":
    a = input("please input an incredient:")
    if a != "quit":
        print(f"{a} will be added!!")

        
please input an incredient:apple
apple will be added!!
please input an incredient:abc
abc will be added!!
please input an incredient:quit

 

2、

>>> tag = True
>>> while tag:
    a = input("please input an incrident: ")
    if a != "quit":
        print(f"{a} will be added!!")
    else:
        tag = False

        
please input an incrident: apple
apple will be added!!
please input an incrident: 100
100 will be added!!
please input an incrident: quit

 

上一篇:php按数组中的时间字段分组


下一篇:Ubuntu 20.04 开机执行自定义脚本