#25 Python Tutorial for Beginners | Prime Number in Python

///#25 Python Tutorial for Beginners | Prime Number in Python

#25 Python Tutorial for Beginners | Prime Number in Python

FavoriteLoadingAdd to favorites

Github :-

source

By |2020-10-02T09:52:49+00:00October 2nd, 2020|Python Video Tutorials|26 Comments

26 Comments

  1. Rohit nain October 2, 2020 at 9:52 am - Reply

    user_input = int(input("Enter your number:"))

    for i in range(2,user_input):

    if (user_input % i == 0):

    print(user_input, "is not a prime number")

    break

    else:

    print(user_input, "is a prime number")

  2. Rahul Mishra October 2, 2020 at 9:52 am - Reply

    num = int(input("Enter a number "))

    for i in range(2,num):
    if num % i == 0:
    print(num , " is not a prime number.")
    break
    else:
    print("Prime")

  3. Nicole Angela October 2, 2020 at 9:52 am - Reply

    love this! thanks for the info!

  4. ZESHAN KHALID October 2, 2020 at 9:52 am - Reply

    #checking whether number is prime or not by getting user input
    num =int(input("Enter your expected number "))
    for i in range(2,num):
    if num%i==0:
    print("Not prime number ")
    break
    else:
    print("Prime number ")
    break

  5. Wilbert Lo October 2, 2020 at 9:52 am - Reply

    Can someone help me if i input 5 the output is 2 3 5 7 11 do you know how?? If you know pls help me i am stuck

  6. Nitin Kumar October 2, 2020 at 9:52 am - Reply

    n = int(input("Enter a Number : "))

    flag = 0

    for i in range(2, n):

    if n % i == 0:

    flag = 1

    break

    if flag == 1:

    print(n , " is not a Prime Number")

    else:

    print(n , " is a Prime Number")

  7. Amit chakraborty October 2, 2020 at 9:52 am - Reply

    Suppose i want to print the dividends also(if not prime) . how can i do that ?? help needed

  8. Dip Paul October 2, 2020 at 9:52 am - Reply

    1 is not a prime num… but in ur code if i put 1… Output 1 is prime num. Just add one code between 1st line nd 2nd line that is if num >1:

  9. Entertain ment October 2, 2020 at 9:52 am - Reply

    Then every number is prime sir

  10. Entertain ment October 2, 2020 at 9:52 am - Reply

    Every number is divisible by 1 and by number itself

  11. tony gowtham October 2, 2020 at 9:52 am - Reply

    def check_prime(n):

    if n == 1:

    return False

    elif n == 2:

    return True

    else:

    for i in range(2,n):

    if n % i == 0:

    return False

    return True

  12. Tankasala Aishwarya October 2, 2020 at 9:52 am - Reply

    from math import sqrt

    n = int(input('Enter a number: '))

    if n%2==0 and n!=2:

    print('Not Prime')

    else:

    for i in range (3,int(sqrt(n))+1,2):

    if n%i==0:

    print('Not Prime')

    break

    else:

    print('Prime')

  13. chandrashekhar Tigercharla October 2, 2020 at 9:52 am - Reply

    Import math
    X = int (input("please enter a number: "))
    For I in range (2,math.ceil(x/2)):
    If x % i ==0:
    Print (" it's not a prime ")
    Break
    Else:
    Print ( " its a prime number")

  14. Raju Chowdary October 2, 2020 at 9:52 am - Reply

    r=int(input("Enter your number:-"))

    for k in range(2,r):

    if r%k==0:

    print("=> Not Prime")

    break

    else:

    print("=> Prime")

  15. Vishal Gawhane October 2, 2020 at 9:52 am - Reply

    Boss Ur amazing person …

  16. vishal vinayak October 2, 2020 at 9:52 am - Reply

    i=int(input("Enter the no to be checked:"))

    a=0

    for b in range (1,i):

    if i%b==0:

    a=a+1

    if a>=2:

    print("Not Prime")

    else:

    print("prime")

  17. SHAHNAWAZ KHAN October 2, 2020 at 9:52 am - Reply

    I know sir aapka mood theek nhi h is video m🙁

  18. urvish pipariya October 2, 2020 at 9:52 am - Reply

    N = int(input ("enter a number')
    If n % 2 == 0:
    Print ("prime)
    Else
    Print (not prime)

  19. bhanu sachdeva October 2, 2020 at 9:52 am - Reply

    thanks Navin….Brilliant teaching method….Kudos

  20. Sou Haechan October 2, 2020 at 9:52 am - Reply

    how do you do it without break?

  21. Dr.Mashup October 2, 2020 at 9:52 am - Reply

    num =int(input('enter a no to check'))
    for i in range(2,int(num/2)+1):

    if num % i ==0:

    print(' not prime')

    break

    else:

    print('prime')

  22. Atharv Pathak October 2, 2020 at 9:52 am - Reply

    how to check for a series or range of numbers? Like, if we don't want to give a specific number as input and we want to check all the numbers from 2-100 if prime or not. So what changes would be there in the code, could someone pls help?

  23. Swapnil Patil October 2, 2020 at 9:52 am - Reply

    num = int(input())

    if num > 2:

    for i in range(2, num):

    if num % i == 0:

    print("NOT Prime")

    break

    else:

    print("Prime")

    else:

    print("Not prime")

  24. Mr. Nobody October 2, 2020 at 9:52 am - Reply

    This works too. Its with while loop. My classes havent reached till for loop yet and i was asked to make it so i made with while loop.
    while True:

    a=int(input('Enter the number'))

    c=int(a/2)

    b=2

    while b<=c:

    if a%b==0:

    print('Composite')

    break

    b=b+1

    else:

    print('Prime')

  25. gautam tiwari October 2, 2020 at 9:52 am - Reply

    can any1 explane me this line : "" for i in range(2,num): ""

  26. Sibgatullah Shovon October 2, 2020 at 9:52 am - Reply

    @telusko: Navin sir , as per condition
    for i in range(2,num):
    if num % i ==0:
    print("not prime")
    If input num is 2 then num%i==0
    So, as per condition it should be not prime though we know it is prime number and python also say so. Could you please explain????

Leave A Comment

*