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
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 ```
Thank you so much
Join our real-time social learning platform and learn together with your friends!