0

problem in python please help

https://code.sololearn.com/cEOUCR3E27aT/#py Can anyone tell me why are the repetition coming?/

5th Jun 2019, 6:52 PM
Rahul guha
Rahul guha - avatar
7 Answers
+ 1
What you are doing is printing the factors of a given numberđŸ€”
5th Jun 2019, 6:57 PM
Trigger
Trigger - avatar
+ 1
Youre getting the repetition from your first “for” loop. Think, each for loop it has to run through all the numbers, and there is no need for 2 loops. Simplify your loop to this, and give it a try. for i in range(2,num+1): if num % i == 0: print(i)
6th Jun 2019, 12:42 PM
Beau Tooley
Beau Tooley - avatar
+ 1
Beau thats just gonna print out the factors of the number (ie. The numbers that can divide into it with no remainder)
6th Jun 2019, 1:20 PM
Trigger
Trigger - avatar
+ 1
Thank you people .......thank you for your support......i got the answer
6th Jun 2019, 5:44 PM
Rahul guha
Rahul guha - avatar
+ 1
Are you using Sieve of Erastothenes?
6th Jun 2019, 5:46 PM
Trigger
Trigger - avatar
0
Thomas Williams, i agree. I did see at the top of the code it says “to print prime numbers”, but that code is missing a couple lines to acheive that. My answer would have been different if he asked why hes not getting primes. But, to answer why hes getting repetition with the code presented, is why i gave that answer:)
6th Jun 2019, 5:47 PM
Beau Tooley
Beau Tooley - avatar
0
đŸ‘đŸŒthe second for loop basically caused his code to repeat a number of times
6th Jun 2019, 6:01 PM
Trigger
Trigger - avatar