0

I am trying to create a program that will spit out a list of numbers that are divisible by a divisor, in a certain range specified by start and stop. The code below does not work as intended. For example: supplying values start = 1, stop = 10, divisor = 3 returns this list: [2, 3, 5, 6, 8, 9] I do not understand why... 2, 5, and 8 should not pass the number % divisor != 0 test, as it evaluates to True. Can someone explain please? Thank you :)

start = int(input("START: "))
stop = int(input("STOP: "))
divisor = int(input("DIVISOR: "))
if divisor <= 0:
    print("Cannot divide by zero")
else:
    user_numbers = list(range(start, stop + 1))
    for number in user_numbers:
        if number % divisor != 0:
            user_numbers.remove(number)
    print(user_numbers)

0 Answers0