Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
problem in python please help
https://code.sololearn.com/cEOUCR3E27aT/#py Can anyone tell me why are the repetition coming?/
7 Respostas
+ 1
What you are doing is printing the factors of a given numberš¤
+ 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)
+ 1
Beau thats just gonna print out the factors of the number (ie. The numbers that can divide into it with no remainder)
+ 1
Thank you people .......thank you for your support......i got the answer
+ 1
Are you using Sieve of Erastothenes?
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:)
0
šš¼the second for loop basically caused his code to repeat a number of times