Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
num+1
#3
alright ! i got it !

okay i have another question:
when i execute the following code:

user_number = int(input("please choose a number to check: "))

list1 = range(2, user_number+1)
list2 = []

for x in list1:
    if user_number % x == 0:
        list2.append(x)
        print(list2)
it gives me the following output:

Output:
please choose a number to check: 30 [2] [2, 3] [2, 3, 5] [2, 3, 5, 6] [2, 3, 5, 6, 10] [2, 3, 5, 6, 10, 15] [2, 3, 5, 6, 10, 15, 30] Process finished with exit code 0
now, why does it give me the whole process of getting to 30 ?
i mean, why doesn't it just write the last result ? (the last line) ?
like, simply: [2, 3, 5, 6, 10, 15, 30]
Reply


Messages In This Thread
num+1 - by astral_travel - Oct-16-2022, 02:15 PM
RE: num+1 - by ndc85430 - Oct-16-2022, 02:36 PM
RE: num+1 - by astral_travel - Oct-16-2022, 02:36 PM
RE: num+1 - by snippsat - Oct-16-2022, 02:51 PM
RE: num+1 - by astral_travel - Oct-16-2022, 02:57 PM
RE: num+1 - by astral_travel - Oct-16-2022, 03:18 PM
RE: num+1 - by ndc85430 - Oct-16-2022, 03:27 PM
RE: num+1 - by Yoriz - Oct-16-2022, 03:32 PM
RE: num+1 - by astral_travel - Oct-16-2022, 06:35 PM
RE: num+1 - by Larz60+ - Oct-17-2022, 01:57 AM
RE: num+1 - by astral_travel - Oct-17-2022, 09:49 AM
RE: num+1 - by ndc85430 - Oct-18-2022, 05:53 AM
RE: num+1 - by astral_travel - Oct-20-2022, 05:23 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020