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

 

3、

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

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

 

posted @ 2021-01-02 14:28  小鲨鱼2018  阅读(87)  评论(0编辑  收藏  举报