Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (anonymous):

Hi I have a question on Pract Quiz1 #5. I posted the question and the code in the pastebin below. Thanks http://pastebin.com/YwLYPwPQ

OpenStudy (turingtest):

*

OpenStudy (rsmith6559):

raw_input() returns a string.

OpenStudy (anonymous):

# The following code contains two semantic errors. Correct it so that it reads in integers until the user enters -1, and then prints the sum of the integers (8 points) def getLines(): inputs = [] while True: line = raw_input('Enter a positive integer, -1 to quit: ') # I have casted the value to int here if int(line) == -1: break # I have casted the value to int here. You can either put it here or in the for loop to convert them while adding them inputs.append(int(line)) # There is no return value in the original code. This should fix it! return inputs total = 0 for e in getLines(): total += e print total

OpenStudy (anonymous):

Thanks everyone. I got it now!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!