Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 While loop in list
#1
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)
buran wrote Nov-08-2019, 03:09 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
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.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Quote
#3
Also note that at the end you are printing the last number (number1), not the list of numbers (my_list).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)