lab2.py 944 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. # Normally, there won't be two assignments overlapping, but we're still testing
  3. # so whatever.
  4. # total should return the sum of the numbers passed in
  5. def total(numbers):
  6. return numbers[0]
  7. # onestring should return 1 the first time it's called and 'ring' the second time
  8. def onestring():
  9. return 1
  10. # Your code will be run in a sandbox, so print statements are not allowed in
  11. # the required functions. The below code gets executed when you run the python
  12. # file; this should aid you in debugging/testing.
  13. if __name__ == '__main__':
  14. list1 = [1, 2, 3]
  15. list2 = [-10, -10, -30]
  16. print 'sum of list1:', total(list1)
  17. print 'sum of list2:', total(list2)
  18. print # blank line
  19. if onestring() == 1:
  20. print 'got 1 the first time!'
  21. else:
  22. print 'onestring didn\'t return 1 the first time :('
  23. if onestring() == 'ring':
  24. print "got 'ring' the second time!"
  25. else:
  26. print "onestring didn't print 'ring' the second time D:"