Advertisement
clockworkpc

Odd and Even numbers, ranges, sums

Jan 10th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Released under a GPLv3 Licence by Clockwork PC 2014
  3. # www.clockworkpc.com.au
  4.  
  5. # You are entitled to the following four freedoms:
  6. # Freedom 0: To run this program for any purpose
  7. # Freedom 1: To study how this program works and change it to make it do what you wish
  8. # Freedom 2: To redistribute copies so you can help your neighbour
  9. # Freedom 3: To distribute copies of your modified version to others
  10.  
  11. # The Sequence of Bridges from #0 to #180
  12. bridgeNumbers = range(181)
  13. print bridgeNumbers
  14. print ""
  15.  
  16. # The sum of the sequence of Bridges
  17. sumBridgeNumbers = sum(bridgeNumbers)
  18. print "The sum of the numerical values of all the bridges is: ",sumBridgeNumbers
  19. print ""
  20.  
  21. # A list of even Bridges
  22. evenBridgesList = [x for x in bridgeNumbers if x % 2 == 0]
  23. print evenBridgesList
  24. print ""
  25.  
  26. # A list of odd Bridges
  27. oddBridgesList = [x for x in bridgeNumbers if x % 2]
  28. print oddBridgesList
  29. print ""
  30.  
  31. # The sum of the even numbers of Bridges
  32. print "The sum of the even Bridges is: ", sum(evenBridgesList)
  33.  
  34. # The sum of the odd numbers of the Bridges
  35. print "The sum of the odd Bridges is: ", sum(oddBridgesList)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement