
▲ 2 r/PythonLearning
I'm trying some test got stuck on a divisor problem.
I was trying to get numbers from 1 to 10 that divide the input number.
This is the code I tried and ended up working
num_list = range(1, 11)
number = int(input('Enter a number: '))
new_list = [x for x in num_list if number % x == 0]
print(new_list)
But I originally tried this version, which didn't wor
num_list = range(1, 11)
number = int(input('Enter a number: '))
new_list = [x for x in num_list if number / x == 0]
print(new_list)
It always gave me an empty list.
Why does "%" work for this problem while "/" doesn't? What’s the right way to think about this?
(Not sure if I'm just overwhelmed and it's a stupid question😅)
u/CoolPotato_0 — 8 days ago