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

Please help me with appending list. I want to print only 1 list contained odd numbers but I don't know why it printed 3 lists ( code is below ): x = int(raw_input('Enter an integer:')) y = int(raw_input('Enter an integer:')) z = int(raw_input('Enter an integer:')) s = [x, y, z] odd = [] for e in s: if e%2 != 0: odd.append(e) print'odd=',odd It printed: odd= [3] odd= [3, 5] odd= [3, 5, 7] Thank you for taking your time answering this question

OpenStudy (e.mccormick):

Well, you are printing every time you append. If you only want to print once, you need to remove the indents in front of the print statment. ``` x = 3 y = 5 z = 6 s = [x, y, z] odd = [] for e in s: if e%2 != 0: odd.append(e) print'odd=',odd ```

OpenStudy (anonymous):

Thank you so much

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!