lab2.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. # Normally, there won't be two assignments overlapping, but we're still testing
  3. # so whatever. You may wish to look to http://effbot.org/zone/python-list.htm
  4. # for help, or the faster-paced http://docs.python.org/tutorial/controlflow.html.
  5. # Also, http://www.saltycrane.com/blog/2008/01/python-variable-scope-notes/ may
  6. # be of use. Note that I do not recommend anything but docs.python.org as a
  7. # general reference.
  8. # total should return the sum of the numbers passed in
  9. def total(numbers):
  10. return numbers[0]
  11. # onestring should return 1 the first time it's called and 'ring' the second time
  12. def onestring():
  13. return 1
  14. if __name__ == '__main__':
  15. list1 = [1, 2, 3]
  16. list2 = [-10, -10, -30]
  17. print 'sum of list1:', total(list1)
  18. print 'sum of list2:', total(list2)
  19. print # blank line
  20. if onestring() == 1:
  21. print 'got 1 the first time!'
  22. else:
  23. print 'onestring didn\'t return 1 the first time :('
  24. if onestring() == 'ring':
  25. print "got 'ring' the second time!"
  26. else:
  27. print "onestring didn't print 'ring' the second time D:"