Python Tutorial: How to find all Prime Numbers in a given range [ Prime Numbers in Python]

Поделиться
HTML-код
  • Опубликовано: 26 янв 2025

Комментарии • 3

  • @memy4460
    @memy4460 2 года назад +3

    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.')

    • @ismailnijazi7991
      @ismailnijazi7991 2 года назад +1

      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

    • @memy4460
      @memy4460 2 года назад +1

      @@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.