#25 Python Tutorial for Beginners | Prime Number in Python

Sdílet
Vložit
  • čas přidán 30. 06. 2024
  • Check out our courses:
    Spring and Microservices Weekend Live Batch : bit.ly/spring-live-weekend
    Coupon: TELUSKO10 (10% Discount)
    Master Java Spring Development : bit.ly/java-spring-cloud
    Udemy Courses:
    Java:- bit.ly/JavaUdemyTelusko
    Spring:- bit.ly/SpringUdemyTelusko
    Java For Programmers:- bit.ly/javaProgrammers
    For More Queries WhatsApp or Call on : +919008963671
    website : courses.telusko.com/
    Instagram : / navinreddyofficial
    Linkedin : / navinreddy20
    TELUSKO Android App : bit.ly/TeluskoApp
    Discord : / discord
    Github :- github.com/navinreddy20/Python-
  • Věda a technologie

Komentáře • 1,1K

  • @BukkaReddy..
    @BukkaReddy.. Před rokem +65

    Sir you always simplifies the problems in a very easy way ,even a slow learner like me get the logics in first attempt.This is the real quality of great teacher.Thankyou.. Jai Hind🇮🇳

  • @johnhazlett3711
    @johnhazlett3711 Před 2 lety +12

    Finally, a clear, concise, easily understood explanation for finding prime. Thanx.

  • @a.v.n.ssripavan5506
    @a.v.n.ssripavan5506 Před 3 lety +12

    Your beginner video's are best in CZcams sir, in this lockdown wanted to be productive and thought of learning python after a lot of playlists and channels your channel has got all the information and tutorial a beginner needs

  • @jitendrakumar-nf9xz
    @jitendrakumar-nf9xz Před 4 lety +16

    one of the Best star teacher on CZcams hats off to you sir

  • @adarshkanojia4192
    @adarshkanojia4192 Před 5 lety +15

    We wants such type of videos from you dear navin sir

  • @forsake5426
    @forsake5426 Před 3 lety +15

    Great Mr Naveen,this is the real trick if you want to be a good programmer..Good job,,,keep doing this,People need to learn.

  • @JoyBoy_11311
    @JoyBoy_11311 Před 3 lety +8

    at first i used to hate for loop and while loop and after watching your and seeing the examples i used to love them sir thanks a lot❤️btw i am aman raj😀

  • @flamboyantperson5936
    @flamboyantperson5936 Před 5 lety +7

    Great great to see you back on Python series. Lovely. Thanks Navin.

  • @selcukdoven
    @selcukdoven Před 5 lety +7

    Thank you. A very useful video. Could you please add this video in python video list so We can reach them easily.

  • @seanpereira8425
    @seanpereira8425 Před 3 lety +15

    Your tutorials makes coding life much more simple :)

  • @_NishaKarki
    @_NishaKarki Před 4 měsíci +4

    num = int(input("Enter the num:")) # taking input
    if num < 2:
    print("Not prime")
    else:
    for i in range(2, num): # iterate over possible divisors
    if num % i == 0:
    print("Not Prime")
    break # if a divisor is found, no need to continue checking
    else:
    print("prime")
    Guys this will also work for 0 and 1 and also for negative numbers.

  • @aakashtiwari3974
    @aakashtiwari3974 Před 5 lety +237

    your python series are great sir ,thanks for this

  • @placement3608
    @placement3608 Před 5 lety +3

    Continuously uploading videos thats a great sign sir

  • @pannadarao5583
    @pannadarao5583 Před 4 lety +72

    x = int (input ("enter your number ? "))
    for i in range (2,x):
    if x%i==0:
    print ('its a non prime number')
    break
    else:
    print ('its a prime number')

    • @shafiquebarudgar8295
      @shafiquebarudgar8295 Před 3 lety +1

      x%i ?? can you explain me this part ?

    • @manpreetsinghpanesar5748
      @manpreetsinghpanesar5748 Před 3 lety +2

      @@shafiquebarudgar8295 it is dividing x with value of i then checking its remainder is equal to 0 or not ( % equals to find remainder not percent)

    • @niyadata
      @niyadata Před 2 lety +6

      how would this code work for 2? if user enters 2, then it will satisfy the condition if x%i==0 since 2%2 =0, and it will print it's non prime number while 2 is a prime number

    • @manpreetsinghpanesar5748
      @manpreetsinghpanesar5748 Před 2 lety

      @@niyadata actually the range function here is using (2,x) in that case if the value of x is also two this function will not give any output as starting is 2 and ending (which is not included in range function ) is also 2 ,[loop will start from 2 and end on 2 not including it which is not feasible] so program will work normally it will print prime as (null % i != 0)

    • @niyadata
      @niyadata Před 2 lety

      @@manpreetsinghpanesar5748 so if the loop will work, then why won't the first condition be checked or run? Why only the else part will work?

  • @adarshabbigeriadarshabbige8004

    Your python series and other technical videos are excellent sir thank you sir it's help me a lot

  • @vivekbhati
    @vivekbhati Před 4 lety +1

    great work navin !!! really enjoying learning Python

  • @dheerajrthamattat4720
    @dheerajrthamattat4720 Před 3 lety +5

    perfect channel..........!!!!!!!!!!!!!!
    I was totally confused with for loop and while loop, i mean didn't know to use it well..after seeing some of ur vids i was happy....and got some idea abt python language....i will see all ur python vids as it's too interesting..
    btw my doubt was what is the code to print all prime numbers from 0 to 100...?

  • @sahebsarkar8330
    @sahebsarkar8330 Před 5 lety +11

    x=int(input("input your number
    "))
    for i in range(2,int(x/2+1)):
    if(x%i==0):
    print("enter number not prime number")
    break;
    else:
    print("enter number is a prime numbere
    ")
    print("SIR YOU RELAY HELP US SO MUCH SO THANK YOU SOOOOOOOOOOOMUCH FOR YOUR EFFORT")

  • @ashishd272
    @ashishd272 Před 3 lety +2

    there's a neat trick using mathematics. for a number n to be prime, it shouldn't be divisible by all the prime numbers till floor(sqrt(n)).

  • @nicole-oe3vu
    @nicole-oe3vu Před 3 lety +3

    love this! thanks for the info!

  • @soniabhattacharjee8697
    @soniabhattacharjee8697 Před 4 lety +3

    Loved it Reddy Sahab...thankxxxx a ton

  • @aayushichoubey8864
    @aayushichoubey8864 Před 4 lety +4

    Plz make a video on Selenium with python and welenium with python🙏🙏plzz ,at least in between the lockdown we learn something new

  • @adarshyadav340
    @adarshyadav340 Před 2 lety

    Found a couple of more efficient methods and then came across sieve of eratosthenes , would love to see a video explainer by you

  • @paigeb1045
    @paigeb1045 Před 4 lety

    Thanks Navin, very cool!

  • @k.manideep2543
    @k.manideep2543 Před 5 lety +28

    My Prime code, for checking prime number there is no need to run the loop till its number. We an even achieve it by running the loop till (num/2)+1. In this way you can reduce half of the effort. Will be useful while checking for large numbers.
    Code :
    num = int(input("check number is prime or not :"))
    for i in range(2,int(num/2)+1):
    if num % i == 0:
    print("not prime")
    break
    else:
    print("prime")

    • @jatinlekhwar6798
      @jatinlekhwar6798 Před 2 lety +1

      You dont have the need to add 1.

    • @MikoKikoJo
      @MikoKikoJo Před 2 lety

      Wouldn't need the second "int" call in the range function. But you probably already know that now :D

    • @martinesse4830
      @martinesse4830 Před 2 lety

      @@jatinlekhwar6798 I think you do, if you don't put 1 then it will return 4 as a prime because the range will be (2,2) and it will go into else, correct me if I am wrong

    • @martinesse4830
      @martinesse4830 Před 2 lety

      @@MikoKikoJo what do you mean, it will throw an error

    • @PsychedelicGuy1
      @PsychedelicGuy1 Před 2 lety +3

      @@MikoKikoJo you have to, if you put any number like 5 in that formula, answer will be 3.5 and range cannot go till 3.5 it needs integer.

  • @arunavsen2234
    @arunavsen2234 Před 5 lety +4

    Sir, take love from Bangladesh

  • @dishantkumbhar8822
    @dishantkumbhar8822 Před 4 lety

    I tried a lot many times to learn code for prime. But didn't worked .
    U r really great 💯🔥

  • @TM-ej9mr
    @TM-ej9mr Před 3 lety

    Best Tutorials series ever I have seen...........

  • @sathyaprasanna8457
    @sathyaprasanna8457 Před 4 lety +5

    LOOKING SMART SIR

  • @anjanakrishnan2073
    @anjanakrishnan2073 Před 2 lety +1

    All these days i was thinking who in the world invented this programming ?......but after watching ur videos i really feel learning programming is fun!!!

  • @bhanusachdeva2136
    @bhanusachdeva2136 Před 3 lety

    thanks Navin....Brilliant teaching method....Kudos

  • @najimali32
    @najimali32 Před 4 lety +11

    we can improve the time by only checking odd divisor till the square root of the given num.
    for eg - num is 29 then check num check by it by 3,5 ,7.

  • @chughprabhkirat4141
    @chughprabhkirat4141 Před 4 lety +17

    num = int(input("Enter any number "))
    if num>1:
    for i in range(2,num):
    if num%i==0:
    print("Not a prime number.")
    break
    else:
    print('it is a prime number')
    else:
    print('not a prime number')

    • @akbarmohammad5081
      @akbarmohammad5081 Před 4 lety

      Why you wrote else conditions two times?

    • @thanishkrishnamurthy1689
      @thanishkrishnamurthy1689 Před 4 lety +1

      @@akbarmohammad5081 One is for "if-else" statement and another is for "For-else" But their is no need for "If-else" if u want you can include

    • @DheerajKumar-yk3yl
      @DheerajKumar-yk3yl Před 3 lety +1

      Could you say why you use break, I'm not under stand by from video

    • @thedmitryguy
      @thedmitryguy Před 3 lety

      dheeraj kumar, because we don’t have to continue dividing ‘num’ by ‘i’. ‘break’ stops ‘for’. For example, ‘num’ = 10, and if 10 % 2 = 0 then this number is definitely not a prime number because prime number can only be divided by itself and by 1, and we don’t have to continue dividing ‘num’ by 3, 4 and so on. Do you understand it now?

    • @lyricathelyricsworld8945
      @lyricathelyricsworld8945 Před 3 lety +1

      num=int(input('enter the number'))
      if num%2==0 or num%3==0 or num%5==0 or num%7==0 and num%num!=0:
      print('not prime')
      else:
      print('prime')
      try this mam

  • @dee347rahulprajapati7
    @dee347rahulprajapati7 Před 2 lety +1

    Same output can be achived by if-else, just using one more "break" in the else part.

  • @kvmcost
    @kvmcost Před 3 lety

    Really simple and interesting. Thanks

  • @sivakrishna3575
    @sivakrishna3575 Před 4 lety +14

    if you want to try with function:
    def prime(num):
    for i in range(2,num):
    if num % i == 0:
    return "not a prime number"
    else:
    return "prime number"
    num = int(input("enter a number: "))
    print(prime(num))

    • @Simranxxkaur
      @Simranxxkaur Před 2 lety

      Hey , do you know how to do this ques?

    • @Simranxxkaur
      @Simranxxkaur Před 2 lety

      Consider a tuple T1 = (1, 2, 5, 7, 9, 3, 4, 6, 8, 10). Write a function primes() that accepts tuple T1 as argument and creates a list T2 having values that are prime numbers in the tuple T1. The function should return a dictionary primeCubes where keys are items of the list T2 and the values are cubes of the keys. For example, when T1 as passed as an argument, T2 will be [2, 5, 7, 3] and primeCubes will be {2:8,5:125,7:343,3:27}.

  • @jayantakumarpal7751
    @jayantakumarpal7751 Před 3 lety +8

    n=int(input("Enter a number"))
    c=0
    for i in range(1,n+1):
    if n%i==0:
    c+=1
    if c==2:
    print("prime")
    else:
    print("Not prime")

    • @zgryx8428
      @zgryx8428 Před 2 lety +1

      Bro the tutorial itself is wrong, your code works perfectly thank you!

    • @ravivishnud384
      @ravivishnud384 Před 2 lety

      Yeah he made a mistake for i in range (1,num+1) should come and the +1 is excluded and it prints 1:num)

  • @alisherxujanov2100
    @alisherxujanov2100 Před 3 lety

    This guy is amazing teacher! Bravvo

  • @NaveenkumarYadav-sg8yh

    We can put IF condition with squr() function to get that division number.If squr() of that number come with greater than zero that means it is division of some number and we dont need to go in the roop condition. we can come out by else.

  • @moazelsawaf2000
    @moazelsawaf2000 Před 5 lety +6

    Really thank you sir, i like this algorithm ❤

  • @medicrohan2686
    @medicrohan2686 Před 5 lety +7

    The other better way is to check if number is divisible by 2 first and then only check for odd numbers upto square root of the number.

    • @raghavendraam719
      @raghavendraam719 Před 11 měsíci

      n=int(input("enter the number you want to check: "))
      for i in range(2,n//2):
      if n%i==0:
      print('its not prime')
      break
      else:
      print("its prime")

    • @raghavendraam719
      @raghavendraam719 Před 11 měsíci

      i m learning now brother.

    • @JyothiKommana
      @JyothiKommana Před 9 měsíci

      ​@@raghavendraam719i did not understand at all😢

  • @rahul141141
    @rahul141141 Před 2 měsíci +1

    Little more optimized..
    import math
    num = int(input("Enter the number:"))
    n = math.floor(math.sqrt(num))
    for i in range(2,n + 1,1):
    if num % i == 0:
    print("The number is not prime, divisible by", i)
    break
    else:
    print("The number is prime")

  • @mahendrapabbathi4621
    @mahendrapabbathi4621 Před 2 lety

    Really u r great sir, excellent explaining in simple code

  • @rahuldev007
    @rahuldev007 Před rokem +5

    num = int(input())
    for i in range(2,num):
    if num%i==0:
    print("not prime")
    break
    else:
    print("prime")

  • @johnsisofia3178
    @johnsisofia3178 Před 4 lety +4

    count=0
    x=int(input("Enter a number:"))
    for i in range(1,x+1):
    if(x%i==0):
    count+=1;
    if(count==2):
    print("Prime")
    else:
    print("Not prime")

    • @chaitanyabandela3063
      @chaitanyabandela3063 Před 2 lety

      Good answer

    • @siddhanthshetty6920
      @siddhanthshetty6920 Před 2 lety

      👏👏👏👏Bravo.
      I had to debug the whole code in order to understand.
      Won't call it efficient but that was creative as hell. 👌

  • @javohirmurodov4670
    @javohirmurodov4670 Před 3 lety

    thank you very much , this video helped me a lot!

  • @rajshekharpenshanwar7420

    😊Enjoyed...Everytimes...!

  • @blessedinspirational
    @blessedinspirational Před 4 lety +5

    You're the best teacher soo far!
    Please how can i found your Java tutorial?

  • @hritwikhaldar9272
    @hritwikhaldar9272 Před 4 lety +7

    x=int(input("Enter any interger number: "))
    for i in range(2,x):
    if x%i==0:
    print("=> it is not a prime")
    break
    else:
    print("=> it is a prime")

  • @ssmondal6789
    @ssmondal6789 Před 3 lety

    First education purpose video without any advertisement 🤩

  • @pratibhachavan4729
    @pratibhachavan4729 Před 4 lety +2

    Thankyou so much you art brilliant . Please can you start teaching java pleasseee

  • @rithvikreddychantigari716

    For this program
    x=int(input("Enter a number"))
    count=0
    for i in range(1,x):
    if x%i==0:
    count=count+1
    if(count>2):
    print("The number is not prime")
    else:
    print("The number is prime")

  • @niharikasingh769
    @niharikasingh769 Před 3 lety +4

    isprime=int(input())
    for i in range(2,int(isprime/2)):
    if isprime%i==0:
    print("not prime")
    break
    else:
    print("Prime")

    • @ganeshmurugan5498
      @ganeshmurugan5498 Před 2 lety

      range(2,i nt(isprime/2)) --> if the input is 4 then range(2, 4/2) --> range(2, 2) --> then else statement will directly executed and print prime

  • @dnyaneshwarkadam6823
    @dnyaneshwarkadam6823 Před 5 lety

    Thanks sir......for python series...
    😊😃😃

  • @untiy497
    @untiy497 Před rokem

    this is the best beginner videos on CZcams

  • @jiya9643
    @jiya9643 Před 4 lety +3

    sir i am getting this error, help me please.
    connection to python debugger failed interappted funtion call accepted failed .

  • @farhanahmed-ws1mb
    @farhanahmed-ws1mb Před 4 lety +10

    i=2
    while(i

  • @akshathashirke5814
    @akshathashirke5814 Před 3 lety

    Video was really helpful. Thanks a lot

  • @vishalgawhane6368
    @vishalgawhane6368 Před 3 lety

    Boss Ur amazing person ...

  • @mohammedimdaad270
    @mohammedimdaad270 Před 4 lety +22

    ♐To get code in an efficient way - just reduce the no. of iterations by half😉
    code:
    num = 25
    for i in range(2,(num//2)):
    if num%i==0:
    print("Not Prime")
    break
    else:
    print("Prime")
    o/p:
    not prime

    • @adithyaramapuram4995
      @adithyaramapuram4995 Před 4 lety +1

      you can make to square root it is more efficient than halfing number

    • @shivendumishra6913
      @shivendumishra6913 Před 2 lety +1

      use seive algo

    • @RickC-ew7zs
      @RickC-ew7zs Před 2 lety

      @@adithyaramapuram4995 brother, you'll have to add 1 after taking the square root. if you directly put sqrt value in range, it won't get included in the code and henceforth resulting in wrong output.

  • @futuristictechnology..531
    @futuristictechnology..531 Před 11 měsíci +46

    welcome back aliens 🤣🤣🤣🤣

  • @nakamoto830
    @nakamoto830 Před rokem +4

    x=int(input("enter an number howle"))
    if x%2==0 :
    print(x,"not prime")
    elif x%3==0 or x%5==0:
    print(x,"not prime")
    else:
    print(x,"prime")

    • @vaishnavi0414
      @vaishnavi0414 Před rokem

      I like the input part 🤣🤣

    • @SarojSingh-vl2kj
      @SarojSingh-vl2kj Před 4 měsíci

      input is 49 output is prime 💀
      but I thought 49 is non prime bro

  • @yaminithalari1531
    @yaminithalari1531 Před 6 měsíci

    Thank you this helped me a lot with my mini project!

  • @voiceofvicky
    @voiceofvicky Před 4 měsíci +1

    count = 0
    n = int(input("Enter a number:"))
    for i in range(1, n+1):
    if n % i == 0:
    count +=1
    if count == 2:
    print(n, "is a Prime number")
    else:
    print(n, "is Not a Prime number")

  • @anwarsheik3329
    @anwarsheik3329 Před 3 lety +4

    There is no need to iterate the for loop upto n-1 just iterate it upto n/2
    Cause a number having a value more than half cannot divide that number
    Then the time complexity will reduce to n/2 time which is n-1 times in your code

    • @khamza8926
      @khamza8926 Před 2 lety +1

      Actually iterating upto floor(n**0.5) is even more efficient

    • @anwarsheik3329
      @anwarsheik3329 Před 2 lety

      @@khamza8926 hi khamza, can you explain your point of view

    • @pepekont3736
      @pepekont3736 Před 10 měsíci

      ​@@anwarsheik3329search for sieve of eratosthenes proof

  • @sibgatullahshovon
    @sibgatullahshovon Před 3 lety +5

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

    • @codifa5847
      @codifa5847 Před 3 lety

      you can add special condition for 2 because its a start from 2

    • @erz_mafia
      @erz_mafia Před 3 lety

      bro when you debug this, range function doesn't allow it to read ' if ' statement it straight away jump to 'else ' statement.

    • @lyricathelyricsworld8945
      @lyricathelyricsworld8945 Před 3 lety +2

      num=int(input('enter the number'))
      if num%2==0 or num%3==0 or num%5==0 or num%7==0 and num%num!=0:
      print('not prime')
      else:
      print('prime')
      try this

  • @subhodeepdas6270
    @subhodeepdas6270 Před 4 lety

    Under what condition does the break outside the for loop work? Does it work if there is no if condition in the for loop? Or does it work only if there is if and all the conditions in the if are not satisfied. What happens if there are 2 if's in the for loop?

  • @anonymoususer900
    @anonymoususer900 Před 3 lety +1

    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

    • @sumeetrox2479
      @sumeetrox2479 Před 3 lety

      Hi can you tell me if the -------> 'else' at the bottom is with 'while true' indentation or with 'while b

    • @anonymoususer900
      @anonymoususer900 Před 3 lety +1

      @@sumeetrox2479 oustide whileb

    • @abhinavmappidichery9371
      @abhinavmappidichery9371 Před 2 lety

      print a prime number, greater than or equal to a given number

  • @neelamgupta2505
    @neelamgupta2505 Před 4 lety +12

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

    • @nashwanth6640
      @nashwanth6640 Před 4 lety +1

      For input 4 it is showing as 4 is prime number but 4 is not prime (factors are 1,2,4)

    • @chikkamchandrasekhar61
      @chikkamchandrasekhar61 Před 4 lety +1

      U should add 1 in range
      range(2,(num//2)+1):
      Then 4 will be a "not prime"....

    • @chikkamchandrasekhar61
      @chikkamchandrasekhar61 Před 4 lety +1

      @Prem Kumar It works....
      For n=2 it directly enters the else part and it becomes a prime number

    • @chikkamchandrasekhar61
      @chikkamchandrasekhar61 Před 4 lety +1

      @Prem Kumar bro here we have to use "for-else" not "if-else"
      Then n=2 enters the else part

    • @chikkamchandrasekhar61
      @chikkamchandrasekhar61 Před 4 lety +1

      @Prem Kumar No bro "if loop" will not execute bcoz
      In range(2,(2//2)+1) is range(2,2) i.e it doesn't enter "if loop"

  • @JatinKumar-gz5gg
    @JatinKumar-gz5gg Před 4 lety +6

    a=int(input("enter a number"))
    count=0
    i=1
    while i

  • @abhinavsamudrala
    @abhinavsamudrala Před 3 lety

    sir this is my efficiently modified by the clue you have given 👇👇
    num = 19
    for i in range (2,int(num/2)):
    if num % i == 0:
    print("not prime")
    break
    else:
    print("prime")

  • @hasandinc1735
    @hasandinc1735 Před 4 lety +2

    'x=int(input("enter the number "))'
    for x in range(3,500):
    mod=2
    kalan=x%mod
    if(kalan==0):
    'print(x,"not prime")'
    while kalan!=0:
    while mod

    • @obsidian_the_exposure
      @obsidian_the_exposure Před 10 měsíci

      It's seems,, there is syntax error, seems after running this code ,it will not be executed

  • @AbdulKareem-maks
    @AbdulKareem-maks Před 4 lety +5

    Sir, the program you wrote is not valid if the given number is 2. Since we are starting from 2, the given number(2) will be divisible and the program will give the output as Not Prime whereas 2 is a Prime number. Any other way around this?

    • @immadisujith1832
      @immadisujith1832 Před rokem

      a=int(input("enter a number "))
      if a==2:
      print("prime")
      for i in range(2,a):
      if a%i==0:
      print("not prime")
      break
      else:
      print("prime")
      break

  • @nikhilpatnaik3466
    @nikhilpatnaik3466 Před 4 lety +3

    from math import *
    x = int(input("Enter the number: "))
    for i in range(2,floor(sqrt(x))+1):
    if x%i==0:
    print("Composite")
    break;
    else:
    print("Prime")

  • @Gopichand-ic9rv
    @Gopichand-ic9rv Před rokem

    The way of explanation is good sir

  • @mohamedyousuf9535
    @mohamedyousuf9535 Před 5 lety

    Thank you so much sir

  • @siddharthrajan616
    @siddharthrajan616 Před 3 lety +42

    sir this code won't work for num=2. Since although 2 is divisible by 2 it is a prime number

  • @003fouzeyafardous8
    @003fouzeyafardous8 Před 5 lety +4

    Love from Bangladesh 🇧🇩🇧🇩😊

  • @akashvadnala7197
    @akashvadnala7197 Před 4 lety

    x=int(input())
    print("2")
    count=1
    for num in range(3,x):
    for i in range(2,x):
    if num%i==0:
    break
    else:
    print(num)
    count+=1
    print("No. of prime numbers less than",x,"= ",count)

  • @101vaibhavmojidra4
    @101vaibhavmojidra4 Před rokem

    Efficiency we can check from 2 to num/2, because if any number is not divisible till it's half number then it's prime.

  • @a_r_u_n7595
    @a_r_u_n7595 Před 4 lety +8

    This is a code which prints all prime numbers from 1 to 50
    for num in range(1,50):
    for i in range(2,num):
    if num%i==0:
    break
    else:
    print(num)

  • @janamshah190
    @janamshah190 Před 3 lety +5

    x= int(input('number=?'))
    If x==1:
    print('neither prime nor composite')
    Elif x==2:
    print('prime')
    Else:
    For i in range(2,x):
    If x%i==0:
    print('not prime')
    Break
    Else:
    print('prime')
    Break
    Print('bye')

    • @anirudh4671
      @anirudh4671 Před rokem

      The last line is an error print() p is small😂

    • @PieArtique
      @PieArtique Před rokem

      ​@@anirudh4671 Huh acting as friendly Console showing error😹

  • @Soumik6691
    @Soumik6691 Před 3 lety

    Hi Sir, Please make a tutorial videos on automation testing tools Selenium with Python and Java

  • @simonimanuelesders7056

    thank you i had a working programm and it really did its job good but everytime i typed in 99 it said it is a prime number but with the break it works now

  • @libanbarise8654
    @libanbarise8654 Před 4 lety +18

    num=int(input("Enter a number:"))
    for i in range(2,num):
    if num%i==0:
    print("Not Prime")
    break
    else:
    print("Prime")

  • @azhanashraf6139
    @azhanashraf6139 Před 2 lety

    we can further cut the range of factors by excluding even numbers as factors of odd numbers
    num = int(input('enter any number'))
    factors_range = range(3, int(num / 2)+1, 2) if num % 2 != 0 else range(2, int(num / 2)+1, 1)
    for i in factors_range:
    if num % i == 0:
    print('number', num, 'is not a prime number, divisible by', i)
    break
    else:
    print('it is a prime number')

  • @isaacabid8774
    @isaacabid8774 Před 7 měsíci

    This really helped, I dont get why my python Professor has to overcomplicate these simple maths question by using tens of different functions and identifiers, Thank you again

  • @shivamsingh-fv5uy
    @shivamsingh-fv5uy Před 5 lety +3

    a=int(input("enter number to check: "))
    check=True
    for i in range(2,int((a/2))) :
    if a%i==0 :
    check=False
    break
    else :
    check=True
    if check==True :
    print("prime")
    else :
    print("not")

  • @abhishek-kapoor
    @abhishek-kapoor Před 5 lety +3

    a=int(input('Enter number:'))
    check = False
    for i in range (2,a):
    if a%i == 0:
    print('its not a prime number')
    check = True
    break
    if check == False:
    print('Its a prime number')

  • @tejaswakchoure9176
    @tejaswakchoure9176 Před 3 lety

    Thank u sir excellent lectures

  • @kiyankm9474
    @kiyankm9474 Před 3 lety

    You are the best 👌👌👌👌👌👌

  • @aakashbisen
    @aakashbisen Před rokem +24

    but what if num=2? how will range(2,2) generate a dataset? will it be blank?

    • @falakchudasama9746
      @falakchudasama9746 Před rokem +12

      Create an Elif condition,
      elif num == 2:
      print(“2 is a prime number”)

    • @gopinathpattanayak9216
      @gopinathpattanayak9216 Před 10 měsíci

      ​@@falakchudasama9746
      And for

    • @user-hf5zn3ty9c
      @user-hf5zn3ty9c Před 10 měsíci +2

      I had the same dobut but when I runed the cmnd with input as 2 it printed number is prime

  • @bikash2510
    @bikash2510 Před 5 lety +3

    a = [ ]
    for x in range (2,50):
    isPrime = True
    for num in range(2, x):
    if x % num == 0:
    isPrime = False
    break
    if isPrime:
    a.append(x)
    print(a)

  • @abhisekkharwar7116
    @abhisekkharwar7116 Před 4 lety

    Thank you sir

  • @omiiishirke8049
    @omiiishirke8049 Před 3 lety

    Thanks for helping sir.....

  • @samthejam5202
    @samthejam5202 Před 4 lety +7

    I know this is a long code, but I think it will be easier to process.
    a = int(input("type here-"))
    b = [2, 3, 5, 7]
    for i in b:
    if a ==i:
    print("prime")
    elif a%i==0 or a==1:
    print("not prime")
    break
    else:
    print("prime")

  • @dailyshorts1164
    @dailyshorts1164 Před rokem +18

    n=int(input("Enter a number to check : "))
    for i in range(2,int(n**0.5)+1):
    if n%i==0:
    print("Not Prime")
    break
    else:
    print("Prime")

    • @venugopal-kh5zc
      @venugopal-kh5zc Před 5 měsíci +1

      Explain that exponent please

    • @dailyshorts1164
      @dailyshorts1164 Před 5 měsíci

      @@venugopal-kh5zc in python "**" is used for exponential.
      Eg. 5^2 is written as 5**2

    • @venugopal-kh5zc
      @venugopal-kh5zc Před 5 měsíci

      @@dailyshorts1164 that is I now sir ...I want why using exponent. What is logic here

    • @venugopal-kh5zc
      @venugopal-kh5zc Před 5 měsíci

      Explain once

    • @dailyshorts1164
      @dailyshorts1164 Před 5 měsíci

      @@venugopal-kh5zc ohh sorry.
      If a given number n is not divisible by any number from 2 to root(n) then it's prime.

  • @yk-mp7bk
    @yk-mp7bk Před 2 lety

    first time on your video. Nice explanation brother👌👌

  • @aayushichoubey8864
    @aayushichoubey8864 Před 4 lety +1

    Plz make the videos on testing with python🙏🙏🙏🙏

  • @AtharvP07
    @AtharvP07 Před 3 lety +3

    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?

    • @jainammadrecha2758
      @jainammadrecha2758 Před 3 lety +2

      It's simple:
      c = range(2,101)
      for i in c:
      for e in range(2,i):
      if i%e==0:
      print(i,'NOT A PRIME No.')
      break
      else:print(i,'IT\'S A PRIME No.')
      Try this you will get all prime nos from 2-100

    • @043jobinjose3
      @043jobinjose3 Před 3 lety +1

      @@jainammadrecha2758 thanks