[Python] python中while语句使用范例代码 →→→→→进入此内容的聊天室

来自 , 2021-03-18, 写在 Python, 查看 122 次.
URL http://www.code666.cn/view/fca758e5
  1. #!/usr/bin/python
  2. # Filename: while.py
  3.  
  4. number = 23
  5. running = True
  6.  
  7. while running:
  8.     guess = int(raw_input('Enter an integer : '))
  9.  
  10.     if guess == number:
  11.         print 'Congratulations, you guessed it.'
  12.         running = False # this causes the while loop to stop
  13.     elif guess < number:
  14.         print 'No, it is a little higher than that'
  15.     else:
  16.         print 'No, it is a little lower than that'
  17. else:
  18.     print 'The while loop is over.'
  19.     # Do anything else you want to do here
  20.  
  21. print 'Done'
  22.  
  23.  
  24. {--输出
  25.  
  26. }--
  27.  
  28. $ python while.py
  29. Enter an integer : 50
  30. No, it is a little lower than that.
  31. Enter an integer : 22
  32. No, it is a little higher than that.
  33. Enter an integer : 23
  34. Congratulations, you guessed it.
  35. The while loop is over.
  36. Done
  37. #//python/4459

回复 "python中while语句使用范例代码"

这儿你可以回复上面这条便签

captcha