0

generate 10 random integers 1-100 store them in a list. Use a loop. Use a second loop to process the list. In this latter loop, display all numbers in the list and determine the sum of the odd numbers and the sum of the even numbers. Display these sums after the second loop has ended. what's wrong?

import random 

randomList = [] # create list 

sumEven= sumOdd = 0 

for x in range(10):

    r = random.randint(1,100) 
    print(r), 
    randomList.append(r) 
for x in range(len(randomList)): 

    if (randomList[x]%2 == 0): #even number 
        sumEven += randomList[x] 
    else: 
        sumOdd += randomList[x] 

print "\nSum of even numbers =",sumEven 

print "Sum of odd numbers =",sumOdd
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
  • 1
    `print` is a function in Python 3.x. You need to use parenthesis: `print(...)`. –  Oct 08 '14 at 22:53
  • but right now when i run the program its not adding the sums? – ANNABELL Oct 08 '14 at 23:22
  • @ANNABELL,looks like your classmate has already asked a question on the subject, have a look here http://stackoverflow.com/questions/26265103/python-stuck-on-skipping-range-values-for-the-sum-of-a-randint-list/26265661#26265661 – Padraic Cunningham Oct 08 '14 at 23:24

1 Answers1

1

In the future, please post the full error message.

That being said, print is a function. You should use parentheses with it.

https://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173