Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #Random10.py
- #Chris Clarke
- #09.10.2014
- '''
- Write a program that generates 10 random integers from 1-100, and stores them
- in a list.?
- Update : Use a loop. Process the list to determine the sum of the odd numbers
- and the sum of the even numbers. Display these sums.
- '''
- import random as r
- random_list = []
- sum_odd = sum_even = 0
- for _ in range(10):
- random_int = r.randint(1, 100)
- random_list.append(random_int)
- print random_int,
- for n in random_list:
- if n%2 == 0: #even number
- sum_even += n
- else:
- sum_odd += n
- print "\nSum of odd numbers is", sum_odd
- print "Sum of even numbers is", sum_even
Advertisement
Add Comment
Please, Sign In to add comment