python 2nd 条件控制之while语句

实例

while True:
    s = input(Enter something : )
    if s == quit:
        break
    print(Length of the string is, len(s))
print(Done)

实例

while True:
    s = input(Enter something : )
    if s == quit:
        break
    else:
        print(Length of the string is, len(s)) 
print(Done)

 

 

实例  猜数字  while语句

number = 23
running = True
while running:
    guess = int(input(Enter an integer : ))
    if guess == number:
        print(Congratulations, you guessed it.)
# 这将导致 while 循环中止
        running = False
    elif guess < number:
        print(No, it is a little higher than that.)
    else:
        print(No, it is a little lower than that.)
else:
        print(The while loop is over.)
# 在这里你可以做你想做的任何事
print(Done)

 

python 2nd 条件控制之while语句

上一篇:82. 删除排序链表中的重复元素 II


下一篇:java io之File类-遍历目录