It is a good video, but I don't understand why the math.sqrt is needed. We did it this way: number = int(input('Type in the number you want ot check: ')) isPrime = True for i in range(2, number): if number % i == 0: isPrime = False if isPrime: print(f'{number} is a prime number.') else: print(f'{number} is not a prime number.')
Lets take 100 as example in your solution we have to loop from 2 to 99 but in the videos solution we will loop from 1 to 10 which is 10 time faster. It is a math rule that says if a number is not divisble by 1 to squre(number) that number is prime number
@@ismailnijazi7991 OMG, of course. I am an idiot. You are right, this is much faster. Sometimes i wonder if I don't have these ideas, can i still be a good programmer? Thanks for the explanation, much appreciated! I subbed to your channel.
It is a good video, but I don't understand why the math.sqrt is needed. We did it this way:
number = int(input('Type in the number you want ot check: '))
isPrime = True
for i in range(2, number):
if number % i == 0:
isPrime = False
if isPrime:
print(f'{number} is a prime number.')
else:
print(f'{number} is not a prime number.')
Lets take 100 as example in your solution we have to loop from 2 to 99 but in the videos solution we will loop from 1 to 10 which is 10 time faster. It is a math rule that says if a number is not divisble by 1 to squre(number) that number is prime number
@@ismailnijazi7991 OMG, of course. I am an idiot. You are right, this is much faster. Sometimes i wonder if I don't have these ideas, can i still be a good programmer? Thanks for the explanation, much appreciated! I subbed to your channel.