+ 6
Your code has two problems: First the range must start at one and not zero. Remember that division by zero is undefined. Second you have written in the conditional structure r% num == 0 that is incorrect because the values of r will always be less than or equal to num, therefore it will not be divisors. The correct answer would be num% r == 0, try it and tell me. My apologies for my english
24th Jan 2021, 1:09 PM
Luis AndrĂ©s Valido Fajardo 🇹đŸ‡ș
Luis AndrĂ©s Valido Fajardo 🇹đŸ‡ș - avatar
+ 5
Suppose I enter 12 as input. According to your code, it will first check if 0 % 12 == 0 then 1 % 12 == 0 2 % 12 == 0 and so on See the problem? Try thinking about what is the value of 2 % 12 and 3 % 12.
24th Jan 2021, 12:56 PM
XXX
XXX - avatar
+ 4
It is because, "r" is the variable of iteration, therefore it should be your divisor, and not the "num" . Another thing is that your starting point of iteration should be 1 and not 0, to avoid ZeroDivisionError.
24th Jan 2021, 12:56 PM
Nicko James Barata
Nicko James Barata - avatar
+ 2
num = int(input()) # enter the number you want to check the divisor of for r in range (0,num+1): if r%num== 0: print(r) Your code will print only 2 values If u will enter 26 and r will be start for 0 to num+ 1 In if condition 0%num==0 this will be true so r will print then r will be 1 . If1%26==0 False this will be true that time when r will be reach at 26 26%26==0 then will print again so total 2 values will be print in your case change your logic.
24th Jan 2021, 1:05 PM
AS Raghuvanshi
AS Raghuvanshi - avatar