#25 Python Tutorial for Beginners | Prime Number in Python

  Рет қаралды 955,094

Telusko

Telusko

Күн бұрын

Telusko Courses:
Spring and Microservices Live Course : bit.ly/springmslive
Coupon: TELUSKO25 (25% Discount)
Industry-Ready Java Spring Microservices Developer Live : bit.ly/JavaMS2
Complete Java Developer Course : bit.ly/Comp-Java-Dev-2
Coupon: TELUSKO20 (20% Discount)
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-

Пікірлер: 1 100
@BukkaReddy..
@BukkaReddy.. Жыл бұрын
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 2 жыл бұрын
Finally, a clear, concise, easily understood explanation for finding prime. Thanx.
@jitendrakumar-nf9xz
@jitendrakumar-nf9xz 4 жыл бұрын
one of the Best star teacher on KZfaq hats off to you sir
@adarshkanojia4192
@adarshkanojia4192 5 жыл бұрын
We wants such type of videos from you dear navin sir
@aakashtiwari3974
@aakashtiwari3974 5 жыл бұрын
your python series are great sir ,thanks for this
@ganeshmane
@ganeshmane 4 жыл бұрын
Thank you
@a.v.n.ssripavan5506
@a.v.n.ssripavan5506 3 жыл бұрын
Your beginner video's are best in KZfaq 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
@forsake5426
@forsake5426 3 жыл бұрын
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.
@seanpereira8425
@seanpereira8425 3 жыл бұрын
Your tutorials makes coding life much more simple :)
@flamboyantperson5936
@flamboyantperson5936 5 жыл бұрын
Great great to see you back on Python series. Lovely. Thanks Navin.
@JoyBoy_11311
@JoyBoy_11311 3 жыл бұрын
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😀
@placement3608
@placement3608 5 жыл бұрын
Continuously uploading videos thats a great sign sir
@adarshabbigeriadarshabbige8004
@adarshabbigeriadarshabbige8004 4 жыл бұрын
Your python series and other technical videos are excellent sir thank you sir it's help me a lot
@_NishaKarki
@_NishaKarki 3 ай бұрын
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.
@selcukdoven
@selcukdoven 5 жыл бұрын
Thank you. A very useful video. Could you please add this video in python video list so We can reach them easily.
@pannadarao5583
@pannadarao5583 3 жыл бұрын
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 2 жыл бұрын
x%i ?? can you explain me this part ?
@manpreetsinghpanesar5748
@manpreetsinghpanesar5748 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 2 жыл бұрын
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 2 жыл бұрын
@@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 2 жыл бұрын
@@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?
@ashishd272
@ashishd272 3 жыл бұрын
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)).
@soniabhattacharjee8697
@soniabhattacharjee8697 4 жыл бұрын
Loved it Reddy Sahab...thankxxxx a ton
@nicole-oe3vu
@nicole-oe3vu 3 жыл бұрын
love this! thanks for the info!
@vivekbhati
@vivekbhati 4 жыл бұрын
great work navin !!! really enjoying learning Python
@rahul141141
@rahul141141 Ай бұрын
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")
@sahebsarkar8330
@sahebsarkar8330 5 жыл бұрын
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")
@narendrasompalli5536
@narendrasompalli5536 5 жыл бұрын
Super
@narendrasompalli5536
@narendrasompalli5536 5 жыл бұрын
But it better x//2insted of x/2
@sahebsarkar8330
@sahebsarkar8330 5 жыл бұрын
You also right. That's why I caste here by int.
@marjugasvoiceout3547
@marjugasvoiceout3547 4 жыл бұрын
Please explain me this part int(x/2+1)
@sahebsarkar8330
@sahebsarkar8330 4 жыл бұрын
@@marjugasvoiceout3547 let x=3 then x/2=1.5 now 1.5+1=2.5 now int(2.5)=2 for the casting float value become int value.
@arunavsen2234
@arunavsen2234 5 жыл бұрын
Sir, take love from Bangladesh
@TM-ej9mr
@TM-ej9mr 3 жыл бұрын
Best Tutorials series ever I have seen...........
@adarshyadav340
@adarshyadav340 2 жыл бұрын
Found a couple of more efficient methods and then came across sieve of eratosthenes , would love to see a video explainer by you
@dheerajrthamattat4720
@dheerajrthamattat4720 3 жыл бұрын
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...?
@aayushichoubey8864
@aayushichoubey8864 4 жыл бұрын
Plz make a video on Selenium with python and welenium with python🙏🙏plzz ,at least in between the lockdown we learn something new
@anjanakrishnan2073
@anjanakrishnan2073 2 жыл бұрын
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 3 жыл бұрын
thanks Navin....Brilliant teaching method....Kudos
@jiya9643
@jiya9643 4 жыл бұрын
sir i am getting this error, help me please. connection to python debugger failed interappted funtion call accepted failed .
@najimali32
@najimali32 4 жыл бұрын
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.
@jagannathana8504
@jagannathana8504 2 жыл бұрын
No..143...has divisor 13.
@kvmcost
@kvmcost 3 жыл бұрын
Really simple and interesting. Thanks
@subhodeepdas6270
@subhodeepdas6270 4 жыл бұрын
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?
@jayantakumarpal7751
@jayantakumarpal7751 3 жыл бұрын
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 2 жыл бұрын
Bro the tutorial itself is wrong, your code works perfectly thank you!
@ravivishnud384
@ravivishnud384 2 жыл бұрын
Yeah he made a mistake for i in range (1,num+1) should come and the +1 is excluded and it prints 1:num)
@k.manideep2543
@k.manideep2543 5 жыл бұрын
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 2 жыл бұрын
You dont have the need to add 1.
@MikoKikoJo
@MikoKikoJo 2 жыл бұрын
Wouldn't need the second "int" call in the range function. But you probably already know that now :D
@martinesse4830
@martinesse4830 2 жыл бұрын
@@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 2 жыл бұрын
@@MikoKikoJo what do you mean, it will throw an error
@PsychedelicGuy1
@PsychedelicGuy1 2 жыл бұрын
@@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.
@paigeb1045
@paigeb1045 4 жыл бұрын
Thanks Navin, very cool!
@dishantkumbhar8822
@dishantkumbhar8822 4 жыл бұрын
I tried a lot many times to learn code for prime. But didn't worked . U r really great 💯🔥
@sivakrishna3575
@sivakrishna3575 4 жыл бұрын
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 2 жыл бұрын
Hey , do you know how to do this ques?
@Simranxxkaur
@Simranxxkaur 2 жыл бұрын
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}.
@moazelsawaf2000
@moazelsawaf2000 5 жыл бұрын
Really thank you sir, i like this algorithm ❤
@alisherxujanov2100
@alisherxujanov2100 3 жыл бұрын
This guy is amazing teacher! Bravvo
@dee347rahulprajapati7
@dee347rahulprajapati7 2 жыл бұрын
Same output can be achived by if-else, just using one more "break" in the else part.
@siddharthrajan616
@siddharthrajan616 3 жыл бұрын
sir this code won't work for num=2. Since although 2 is divisible by 2 it is a prime number
@onkarparandwal2386
@onkarparandwal2386 2 жыл бұрын
it works
@duleonshio
@duleonshio 2 жыл бұрын
big brain
@chinnidivi8140
@chinnidivi8140 2 жыл бұрын
@@onkarparandwal2386 how it works?
@jprak1329
@jprak1329 Жыл бұрын
2 is the even prime number.
@myatnoemaung2937
@myatnoemaung2937 Жыл бұрын
2 is a prime number
@nakamoto830
@nakamoto830 Жыл бұрын
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 Жыл бұрын
I like the input part 🤣🤣
@SarojSingh-vl2kj
@SarojSingh-vl2kj 3 ай бұрын
input is 49 output is prime 💀 but I thought 49 is non prime bro
@untiy497
@untiy497 Жыл бұрын
this is the best beginner videos on KZfaq
@javohirmurodov4670
@javohirmurodov4670 3 жыл бұрын
thank you very much , this video helped me a lot!
@sathyaprasanna8457
@sathyaprasanna8457 4 жыл бұрын
LOOKING SMART SIR
@medicrohan2686
@medicrohan2686 5 жыл бұрын
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 11 ай бұрын
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 11 ай бұрын
i m learning now brother.
@JyothiKommana
@JyothiKommana 8 ай бұрын
​@@raghavendraam719i did not understand at all😢
@ssmondal6789
@ssmondal6789 3 жыл бұрын
First education purpose video without any advertisement 🤩
@mahendrapabbathi4621
@mahendrapabbathi4621 Жыл бұрын
Really u r great sir, excellent explaining in simple code
@rahuldev007
@rahuldev007 Жыл бұрын
num = int(input()) for i in range(2,num): if num%i==0: print("not prime") break else: print("prime")
@yaminithalari1531
@yaminithalari1531 5 ай бұрын
Thank you this helped me a lot with my mini project!
@pratibhachavan4729
@pratibhachavan4729 4 жыл бұрын
Thankyou so much you art brilliant . Please can you start teaching java pleasseee
@aakashbisen
@aakashbisen Жыл бұрын
but what if num=2? how will range(2,2) generate a dataset? will it be blank?
@falakchudasama9746
@falakchudasama9746 Жыл бұрын
Create an Elif condition, elif num == 2: print(“2 is a prime number”)
@gopinathpattanayak9216
@gopinathpattanayak9216 9 ай бұрын
​@@falakchudasama9746 And for
@user-hf5zn3ty9c
@user-hf5zn3ty9c 9 ай бұрын
I had the same dobut but when I runed the cmnd with input as 2 it printed number is prime
@hritwikhaldar9272
@hritwikhaldar9272 4 жыл бұрын
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")
@AbhishekGupta-di6ol
@AbhishekGupta-di6ol 4 жыл бұрын
Hritwik Haldar it is same bro .... not efficient
@viraldance2303
@viraldance2303 3 жыл бұрын
bto agr input 1 ho toh kaise kroge ??
@akshathashirke5814
@akshathashirke5814 3 жыл бұрын
Video was really helpful. Thanks a lot
@beastprimebp
@beastprimebp 2 жыл бұрын
Thankyou sir for explaining from scratch
@AbdulKareem-maks
@AbdulKareem-maks 4 жыл бұрын
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 11 ай бұрын
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
@chughprabhkirat4141
@chughprabhkirat4141 4 жыл бұрын
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 3 жыл бұрын
Why you wrote else conditions two times?
@thanishkrishnamurthy1689
@thanishkrishnamurthy1689 3 жыл бұрын
@@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 3 жыл бұрын
Could you say why you use break, I'm not under stand by from video
@thedmitryguy
@thedmitryguy 3 жыл бұрын
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 3 жыл бұрын
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
@narenbs1
@narenbs1 Ай бұрын
@Navin: In this code, if num = 2, then the execution does not enter the for loop right?
@Gopichand-ic9rv
@Gopichand-ic9rv 11 ай бұрын
The way of explanation is good sir
@mohammedimdaad270
@mohammedimdaad270 4 жыл бұрын
♐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 4 жыл бұрын
you can make to square root it is more efficient than halfing number
@shivendumishra6913
@shivendumishra6913 2 жыл бұрын
use seive algo
@RickC-ew7zs
@RickC-ew7zs 2 жыл бұрын
@@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.
@johnsisofia3178
@johnsisofia3178 3 жыл бұрын
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 2 жыл бұрын
Good answer
@siddhanthshetty6920
@siddhanthshetty6920 2 жыл бұрын
👏👏👏👏Bravo. I had to debug the whole code in order to understand. Won't call it efficient but that was creative as hell. 👌
@typicalgirl5535
@typicalgirl5535 4 жыл бұрын
Help please!! I'm trying to additionally get the array with the common factors for non-prime nos. with the below code: from array import * a=55 n=array('i',[ ]) for i in range(2,a): if b%i==0: n.append(i) print("not prime",n) I'm not able to add the else clause with the right indentation to print "prime" just once if the no. is actually a prime no.
@voiceofvicky
@voiceofvicky 3 ай бұрын
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")
@blessedinspirational
@blessedinspirational 4 жыл бұрын
You're the best teacher soo far! Please how can i found your Java tutorial?
@rihanentertainment6380
@rihanentertainment6380 4 жыл бұрын
go to playlist.
@sibgatullahshovon
@sibgatullahshovon 3 жыл бұрын
@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 3 жыл бұрын
you can add special condition for 2 because its a start from 2
@erz_mafia
@erz_mafia 3 жыл бұрын
bro when you debug this, range function doesn't allow it to read ' if ' statement it straight away jump to 'else ' statement.
@lyricathelyricsworld8945
@lyricathelyricsworld8945 3 жыл бұрын
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
@dnyaneshwarkadam6823
@dnyaneshwarkadam6823 5 жыл бұрын
Thanks sir......for python series... 😊😃😃
@rajshekharpenshanwar7420
@rajshekharpenshanwar7420 4 жыл бұрын
😊Enjoyed...Everytimes...!
@janamshah190
@janamshah190 3 жыл бұрын
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 Жыл бұрын
The last line is an error print() p is small😂
@PieArtique
@PieArtique Жыл бұрын
​@@anirudh4671 Huh acting as friendly Console showing error😹
@003fouzeyafardous8
@003fouzeyafardous8 5 жыл бұрын
Love from Bangladesh 🇧🇩🇧🇩😊
@suryauikey7673
@suryauikey7673 5 жыл бұрын
Fouzeya Fardous 👍👍👍
@NaveenkumarYadav-sg8yh
@NaveenkumarYadav-sg8yh 5 жыл бұрын
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.
@rgokul6212
@rgokul6212 4 жыл бұрын
Sir without else u can directly print out of for loop??
@niharikasingh769
@niharikasingh769 3 жыл бұрын
isprime=int(input()) for i in range(2,int(isprime/2)): if isprime%i==0: print("not prime") break else: print("Prime")
@ganeshmurugan5498
@ganeshmurugan5498 2 жыл бұрын
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
@rithvikreddychantigari716
@rithvikreddychantigari716 4 жыл бұрын
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")
@roshansingh8258
@roshansingh8258 4 жыл бұрын
Sorry,but it is wrong
@PassionateSaksham
@PassionateSaksham 2 жыл бұрын
Yes Its Wrong
@isaacabid8774
@isaacabid8774 7 ай бұрын
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
@topgameplay4897
@topgameplay4897 3 жыл бұрын
I love your way of explaining,as you first do it wrong,then tell us the write method. Thank You 😀😀
@anwarsheik3329
@anwarsheik3329 3 жыл бұрын
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 Жыл бұрын
Actually iterating upto floor(n**0.5) is even more efficient
@anwarsheik3329
@anwarsheik3329 Жыл бұрын
@@khamza8926 hi khamza, can you explain your point of view
@pepekont3736
@pepekont3736 9 ай бұрын
​@@anwarsheik3329search for sieve of eratosthenes proof
@nikhilpatnaik3466
@nikhilpatnaik3466 4 жыл бұрын
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")
@BeUniqueMotivation
@BeUniqueMotivation 3 жыл бұрын
Instead of floor use ceil and don't add it
@nikhildhongdiya1586
@nikhildhongdiya1586 3 жыл бұрын
Correct
@nikhilpatnaik3466
@nikhilpatnaik3466 3 жыл бұрын
@@BeUniqueMotivation yeah thank you
@101vaibhavmojidra4
@101vaibhavmojidra4 Жыл бұрын
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.
@anonymoususer900
@anonymoususer900 3 жыл бұрын
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 3 жыл бұрын
Hi can you tell me if the -------> 'else' at the bottom is with 'while true' indentation or with 'while b
@anonymoususer900
@anonymoususer900 3 жыл бұрын
@@sumeetrox2479 oustide whileb
@abhinavmappidichery9371
@abhinavmappidichery9371 2 жыл бұрын
print a prime number, greater than or equal to a given number
@AtharvP07
@AtharvP07 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 3 жыл бұрын
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 3 жыл бұрын
@@jainammadrecha2758 thanks
@JatinKumar-gz5gg
@JatinKumar-gz5gg 4 жыл бұрын
a=int(input("enter a number")) count=0 i=1 while i
@mohammadshafaq3685
@mohammadshafaq3685 4 жыл бұрын
a=int(input("enter a number")) count=0 i=2 while i
@ARYAN_1651
@ARYAN_1651 4 жыл бұрын
If there were multiple values divisible by 5 then we will have remove brake and after it will show not found. Do we solution for this
@vishalgawhane6368
@vishalgawhane6368 3 жыл бұрын
Boss Ur amazing person ...
@farhanahmed-ws1mb
@farhanahmed-ws1mb 4 жыл бұрын
i=2 while(i
@mohitsonheriya7605
@mohitsonheriya7605 4 жыл бұрын
What is x
@libanbarise8654
@libanbarise8654 4 жыл бұрын
num=int(input("Enter a number:")) for i in range(2,num): if num%i==0: print("Not Prime") break else: print("Prime")
@electricpajamas6736
@electricpajamas6736 4 жыл бұрын
I did same lol
@pavankumar-nr4mv
@pavankumar-nr4mv 3 жыл бұрын
@@prajithraj9547 no it will print not prime only check once
@gokulkannank3053
@gokulkannank3053 3 жыл бұрын
All prime numbers are greater one After Enter the value Use if num>1
@shubhamgodhani8284
@shubhamgodhani8284 3 жыл бұрын
Bhai sir ne copy marne ko nai bola tha. Dusri method use karo aur sikho
@yk-mp7bk
@yk-mp7bk 2 жыл бұрын
first time on your video. Nice explanation brother👌👌
@abhinavsamudrala
@abhinavsamudrala 3 жыл бұрын
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")
@a_r_u_n7595
@a_r_u_n7595 4 жыл бұрын
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)
@mathmagic5579
@mathmagic5579 4 жыл бұрын
2 print nhi hoga
@leozarni9570
@leozarni9570 4 жыл бұрын
what if we want to just print the NON prime numbers?
@akashvadnala7197
@akashvadnala7197 4 жыл бұрын
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)
@hasandinc1735
@hasandinc1735 4 жыл бұрын
'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 10 ай бұрын
It's seems,, there is syntax error, seems after running this code ,it will not be executed
@chandrashekhartigercharla1633
@chandrashekhartigercharla1633 3 жыл бұрын
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")
@gandhamakhileshkumar4242
@gandhamakhileshkumar4242 2 жыл бұрын
It doesn't work for number 4
@neelamgupta2505
@neelamgupta2505 4 жыл бұрын
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 4 жыл бұрын
For input 4 it is showing as 4 is prime number but 4 is not prime (factors are 1,2,4)
@chikkamchandrasekhar61
@chikkamchandrasekhar61 4 жыл бұрын
U should add 1 in range range(2,(num//2)+1): Then 4 will be a "not prime"....
@chikkamchandrasekhar61
@chikkamchandrasekhar61 4 жыл бұрын
@Prem Kumar It works.... For n=2 it directly enters the else part and it becomes a prime number
@chikkamchandrasekhar61
@chikkamchandrasekhar61 4 жыл бұрын
@Prem Kumar bro here we have to use "for-else" not "if-else" Then n=2 enters the else part
@chikkamchandrasekhar61
@chikkamchandrasekhar61 4 жыл бұрын
@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"
@aayushichoubey8864
@aayushichoubey8864 4 жыл бұрын
Plz make the videos on testing with python🙏🙏🙏🙏
@simonimanuelesders7056
@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
@bikash2510
@bikash2510 5 жыл бұрын
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)
@swagatikamishra4666
@swagatikamishra4666 4 жыл бұрын
thnx
@Soumik6691
@Soumik6691 2 жыл бұрын
Hi Sir, Please make a tutorial videos on automation testing tools Selenium with Python and Java
@ram_rahim_creations_officials
@ram_rahim_creations_officials 5 жыл бұрын
Hi sir.. can i write matrix code in Notepad text editor and run that code using CMD prompt
@nimeshsoni5335
@nimeshsoni5335 5 жыл бұрын
Yes you can
@khushboopandey7983
@khushboopandey7983 4 жыл бұрын
Num =int(input("enter a No.")) For i in range(2,num): If num%i==0: Print("not prime") Break else: Print("prime")
@pranshupandey5907
@pranshupandey5907 4 жыл бұрын
I did same but not working well
@thanishkrishnamurthy1689
@thanishkrishnamurthy1689 3 жыл бұрын
@@pranshupandey5907 It is because, In first line "Num" is in Cap letter Try to make as same for all "num"
@supercoolkartik
@supercoolkartik 3 жыл бұрын
Just printing the num which we enter
@dippaul301
@dippaul301 3 жыл бұрын
Just add one code between 1st nd 2nd line that is -if num>1:
@kondareddymunagala1336
@kondareddymunagala1336 3 жыл бұрын
What if i enter 2 because it's a prime number
@raxxdinus3908
@raxxdinus3908 4 жыл бұрын
in most of the cases this algorithm shows time limit error,can we have a new algo?
@rihanentertainment6380
@rihanentertainment6380 4 жыл бұрын
you can implement this code using square root. that's can be efficient.
@omiiishirke8049
@omiiishirke8049 3 жыл бұрын
Thanks for helping sir.....
#26 Python Tutorial for Beginners | Array in Python
15:57
Telusko
Рет қаралды 1,2 МЛН
PRIME NUMBER PROGRAM IN PYTHON PROGRAMMING || PYTHON PROGRAMMING
7:45
Sundeep Saradhi Kanthety
Рет қаралды 74 М.
Универ. 13 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:07:11
Комедии 2023
Рет қаралды 3,4 МЛН
Sprinting with More and More Money
00:29
MrBeast
Рет қаралды 170 МЛН
PINK STEERING STEERING CAR
00:31
Levsob
Рет қаралды 18 МЛН
#38 Python Tutorial for Beginners | Fibonacci Sequence
8:01
Telusko
Рет қаралды 762 М.
#20 Python Tutorial for Beginners | While Loop in Python
12:43
Telusko
Рет қаралды 1,5 МЛН
#44 Python Tutorial for Beginners | Decorators
7:33
Telusko
Рет қаралды 578 М.
Check If A Number Is Prime | Python Example
11:16
Portfolio Courses
Рет қаралды 7 М.
Python Tutorial - Prime Numbers | Printing Prime Numbers in Given Interval
18:33
Очиститель экрана • 160418185                       Делюсь обзорами в профиле @lykofandrei
0:14
Best Beast Sounds Handsfree For Multi Phone
0:42
MUN HD
Рет қаралды 340 М.
Где раздвижные смартфоны ?
0:49
Не шарю!
Рет қаралды 793 М.
WWDC 2024 - June 10 | Apple
1:43:37
Apple
Рет қаралды 10 МЛН
Bluetooth Desert Eagle
0:27
ts blur
Рет қаралды 5 МЛН
Интереснее чем Apple Store - шоурум BigGeek
0:42