python中while循环使用标志

 

1、

>>> tag = True
>>> while tag:
    a = input("please input something : ")
    if a == "quit":
        tag = False
    else:
        print(a)

        
please input something : 100
100
please input something : abc
abc
please input something : quit

 

2、

>>> tag = True
>>> while tag:
    a = input("please input something:")
    b = int(input("please input an num: "))
    if a == "quit":
        tag = False
    else:
        print(a)
    if b % 2 == 0:
        tag = False
    else:
        print(b)

        
please input something:abc
please input an num: 15
abc
15
please input something:quit
please input an num: 15
15

 

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