我只是试图创建一个所有可能被用户给定数字整除的数字的列表,而且我不太确定如何去做。.我以为itertools
将可以,但是在第5行出现错误Expected Collection.Iterable, got 'int' instead
。确实只是在寻找解决此问题的任何方法。预先感谢!
import itertools
num = int(input('please enter a number'))
list_range = itertools.count
divisor_list = []
for number in list_range:
if num % number == 0:
divisor_list.append(number)
print(divisor_list)
也尝试了这一点,但没有任何运气:
num = int(input('please enter a number'))
list_range = 0, 1
divisor_list = []
while list_range < num:
for number in list_range:
if num % number == 0:
divisor_list.append(number)
list_range += 1
print(divisor_list)