do_while.py 241 B

123456789101112131415161718
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # 计算1+2+3+...+100:
  4. sum = 0
  5. n = 1
  6. while n <= 100:
  7. sum = sum + n
  8. n = n + 1
  9. print(sum)
  10. # 计算1x2x3x...x100:
  11. acc = 1
  12. n = 1
  13. while n <= 100:
  14. acc = acc * n
  15. n = n + 1
  16. print(acc)