Python Forum
coding help lists, loops, and if statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
coding help lists, loops, and if statement
#5
My new code:
number = int(input("Enter a number for which you want to know all the divisors  "))
divisors = []
pdiv = range(1, number + 1)
i = number
while i >= 1:
    check = number % i
    if check == 0:
        divisors.append(i)
    i -= 1
print(str(divisors) + " are the divisors of " + str(number))
Reply


Messages In This Thread
RE: coding help lists, loops, and if statement - by ilondire05 - Jul-19-2019, 12:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,558 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,467 Mar-20-2019, 08:01 PM
Last Post: stillsen
  Problems with For Loops and Lists Sagramor72 2 2,254 Mar-04-2019, 01:26 PM
Last Post: Sagramor72

Forum Jump:

User Panel Messages

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