While loop in list - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: While loop in list (/thread-22326.html) |
While loop in list - TheGhostKnight - Nov-08-2019 Hello! I'am currently taking a programming course in school and we have a project that is individual and we can't ask our teacher for help but we can ask on forums, so i came here looking for help. My Task is to make 3 lists listing all even numbers between 50 and 100 using 3 different ways of making a list using conditions. I'm currently stuck with a problem regarding my while loop and i can't figure out why it won't append the numbers in a list. Here is my code: my_list = [] number_1=50 while True: my_list.append(number_1) number_1 = number_1+2 if number_1== 100: break print(number_1) RE: While loop in list - perfringo - Nov-08-2019 If indentation is correct this should work. I observe that 'all even numbers between 50 and 100' includes 50 but not 100 in this code. RE: While loop in list - ichabod801 - Nov-08-2019 Also note that at the end you are printing the last number (number1), not the list of numbers (my_list). |