Python Forum

Full Version: While loop in list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
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.
Also note that at the end you are printing the last number (number1), not the list of numbers (my_list).