brilliant_moves

Random10.py

Oct 9th, 2014
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. #!/usr/bin/python
  2. #Random10.py
  3. #Chris Clarke
  4. #09.10.2014
  5.  
  6. '''
  7. Write a program that generates 10 random integers from 1-100, and stores them
  8. in a list.?
  9. Update : Use a loop. Process the list to determine the sum of the odd numbers
  10. and the sum of the even numbers. Display these sums.
  11. '''
  12.  
  13. import random as r
  14. random_list = []
  15. sum_odd = sum_even = 0
  16.  
  17. for _ in range(10):
  18.     random_int = r.randint(1, 100)
  19.     random_list.append(random_int)
  20.     print random_int,
  21.    
  22. for n in random_list:
  23.     if n%2 == 0: #even number
  24.         sum_even += n
  25.     else:
  26.         sum_odd += n
  27.  
  28. print "\nSum of odd numbers is", sum_odd
  29. print "Sum of even numbers is", sum_even
Advertisement
Add Comment
Please, Sign In to add comment