python 2nd 条件控制之while语句

2021/8/28 14:07:01

本文主要是介绍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语句的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程