Python Program to Check Prime Number - Complete Guide | Python Tutorial

  Рет қаралды 116,942

WsCube Tech

WsCube Tech

Күн бұрын

Пікірлер: 99
@wscubetech
@wscubetech 2 жыл бұрын
😎Hey, thanks for watching! We’d love to know your thoughts/doubts here in the comments. 👉For professional self-paced certification courses (pre-recorded), visit: bit.ly/Pre-Recorded-Course 👉Don’t forget to SUBSCRIBE to our channel for more such videos & valuable content: bit.ly/KZbin-WsCubeTech
@ihaveitinme638
@ihaveitinme638 Жыл бұрын
def prime_number(n): if n==1: b=print(n,":not prime") return b if n>1: for i in range(2,n): if n%i==0: c=print(n,":not prime") return c break else: print(n,":prime number") n=int(input("enter number:")) prime_number(n)
@BMWCLASSICS_
@BMWCLASSICS_ 5 ай бұрын
bro i think in last we also have to put break when i run it on my pc it shows 2 output
@AbCd-n3j
@AbCd-n3j 3 ай бұрын
Bero 2 is also a prime no. Thia code ia not working for 2
@Hindustani-dl8lp
@Hindustani-dl8lp Ай бұрын
Wow bro
@sakshimourya5418
@sakshimourya5418 Жыл бұрын
you deserve more likes, cleared my concept completely.
@GoGetSP
@GoGetSP 5 ай бұрын
num=int(input("Enter a num to check whether prime or not:")) if num == 1: print(num,"is not a prime number.") elif num == 2: print(num,"is the smallest prime number.") else: for i in range(2,num): if num % i ==0: print(num," is not a prime number.") else: print(num,"is a prime number.") break
@VARADHARLIKAR-ul1oc
@VARADHARLIKAR-ul1oc 6 ай бұрын
def prime_number(n): if n==1: b=print(n,"is not an prime number") return b if n>1: for i in range(2,n): if n%i==0: c=print(n,"is not an prime number") return c break else: print(n,"is prime number") n=int(input("enter the number to check :")) prime_number(n)
@Raj-v8j5u
@Raj-v8j5u Жыл бұрын
Thanks mam. Even telusko hadnt explained this topic this superb. It helped me who is from no CS background.
@sushantchougale6818
@sushantchougale6818 2 жыл бұрын
Thank you very much 😊 ☺️
@gauravpandey9739
@gauravpandey9739 10 ай бұрын
You are amazing mam❤
@itsonlytech8251
@itsonlytech8251 2 жыл бұрын
Nice Information
@Anubhav_Sh_
@Anubhav_Sh_ 11 ай бұрын
very helpful playlist.
@comingsoon..4258
@comingsoon..4258 10 ай бұрын
computer science students attendance here
@Bunty759
@Bunty759 7 ай бұрын
Present sir
@PavitraShukla205
@PavitraShukla205 13 күн бұрын
Your loop checks divisors up to num - 1. While this works, it is not efficient for larger numbers. You only need to check divisors up to the square root of the number (int(num**0.5) + 1). This is because if a number n has a factor larger than its square root, it must also have a smaller factor below the square root.
@niraj_cn
@niraj_cn 2 жыл бұрын
Nice video
@00__mdasif
@00__mdasif 2 жыл бұрын
We wanna deep sir python videos please upload plz....
@Naresh-Bhaydiya-Programmer
@Naresh-Bhaydiya-Programmer 2 жыл бұрын
Grateful
@tabariqawabullah0626
@tabariqawabullah0626 Жыл бұрын
Great video. But This code is saying 9,15,21... are prime numbers but they are not. Any idea why?
@madiripadma3877
@madiripadma3877 Жыл бұрын
Prime number means the number divisible by 1 and itself.for eg : 5 5 is divisible by 1 and 5 only so it is prime number.
@AdityaThakur-cq1ov
@AdityaThakur-cq1ov Жыл бұрын
I think something wrong with this code.... it's say 49 is prime .....kese......
@karthikchinna3621
@karthikchinna3621 Жыл бұрын
You need to add break statment
@anud1917
@anud1917 Жыл бұрын
# 11:program to check if any given number is a prime number. num = int(input("enter the number")) if num
@sapisgreat
@sapisgreat 11 ай бұрын
doesnt work with 0
@asishkumarpatro5903
@asishkumarpatro5903 9 ай бұрын
​@@sapisgreatwill work bhai
@sapisgreat
@sapisgreat 9 ай бұрын
@@asishkumarpatro5903 didnt for me
@I.agri.
@I.agri. 4 ай бұрын
@@sapisgreat that's because 0 is neither a prime nor a composite.
@asifcreative6436
@asifcreative6436 2 ай бұрын
Not working for 2
@oxivrushab2573
@oxivrushab2573 Жыл бұрын
num=float(input(" enter the number ")) if(num%2==0)or(num%3==0)or(num%4==0)or(num%5==0)or(num%6==0)or(num%7==0)or(num%8==0)or(num%9==0)or(num%11==0): print( " number is not prime") else: print(" the numver is prime")
@Mr.Regaltos
@Mr.Regaltos Жыл бұрын
it will say 13 is not prime wrong
@asishkumarpatro5903
@asishkumarpatro5903 9 ай бұрын
Bhai infinite prime h tu aise nahi kar sakta
@kabeersharma6403
@kabeersharma6403 Жыл бұрын
Thanku Thanku Thanku Thanku
@ronak-myself
@ronak-myself 2 жыл бұрын
Sb samajh agya
@gtdforum
@gtdforum Жыл бұрын
Is there a need for a for loop in this example
@adityatorane1234
@adityatorane1234 Ай бұрын
num=int(input("enter num:-")) if(num%2): print("it is prime number") else: print("it is not a prime number") this code is also working to check prime number
@Arun_Pundhir007
@Arun_Pundhir007 27 күн бұрын
Does it work for 2??
@sohebsk2196
@sohebsk2196 Жыл бұрын
this code does not hold for some numbers,,,here isthe correct version: n=int(input("ENTER A NUMBER=")) if n
@asishkumarpatro5903
@asishkumarpatro5903 9 ай бұрын
2 is prime brother
@Zapoodle8
@Zapoodle8 Ай бұрын
@@asishkumarpatro5903 yes...
@khushiv2003
@khushiv2003 Жыл бұрын
n=int(input()) if n==1: print('n is not prime') elif n==2: print('n is prime') else: for i in range(2,n): if n%i==0: print('n is not prime') break else: print('n is prime')
@rushijadhav6903
@rushijadhav6903 6 ай бұрын
What about 99,15,21,25 they are not prime number
@Vivekyaadavvlogs
@Vivekyaadavvlogs 2 ай бұрын
@prittamsingh4453
@prittamsingh4453 Жыл бұрын
mam which software you are using
@prinjaymandani7419
@prinjaymandani7419 Жыл бұрын
pycharm
@AbCd-n3j
@AbCd-n3j 3 ай бұрын
2 is also a prime number and this code wont workjng on 2
@abhijeetsinghyadav8988
@abhijeetsinghyadav8988 9 ай бұрын
n= int(input("Enter any number: ")) if (n%n==0) and (n%2!=0) and (n>1): print("Given number is a prime ") else: print("No is not a prime ")
@akashrai5253
@akashrai5253 8 ай бұрын
This same condition is apply to many numbers like 15 when it is divided by 2 it will not return 0 but it is not a prime number, so this condition will not work even mam's condition is also not working.
@statusvideo2701
@statusvideo2701 Жыл бұрын
Which platform(application) maam is using to run python code ... Please someone reply...
@shubham_gaming-i2v
@shubham_gaming-i2v Жыл бұрын
pi charm
@manjari400
@manjari400 Жыл бұрын
This code is not working appropriately for 2 and the odd numbers that are non prime number like 15,21,9 etc.
@AshishVerma13yq
@AshishVerma13yq 11 ай бұрын
Same doubt
@Staredits006
@Staredits006 10 ай бұрын
Same
@badalmishra7395
@badalmishra7395 9 ай бұрын
It is working fine. I think the problem you got is with "else" . You need to shift it as she said backwards
@asishkumarpatro5903
@asishkumarpatro5903 9 ай бұрын
​@@badalmishra7395but shouldn't if and else statements be in the same indentation?
@badalmishra7395
@badalmishra7395 9 ай бұрын
@@asishkumarpatro5903 yes correct. But in this case if you use the same indentation as "if" in the for loop, it will throw "it is a prime number " multiple time , to break that loop for the output printed once, we need to get that else out of that for loop indentation or use the same indentation used for "for loop" statement. Secondly else should be the same indentation as "if" -True , but , here we have 3 ifs', and the code determines what should be the indentation of else. That's how loop function works
@bgmiviralshort
@bgmiviralshort 2 жыл бұрын
Good
@itzmasum1079
@itzmasum1079 2 жыл бұрын
With this code please try input "2"
@Aditya_Deshmukh
@Aditya_Deshmukh Жыл бұрын
x =int(input("Enter Your Number Please: ")) if x == 2: print("A Prime Number.") else: for i in range(2,x): if x % i == 0: print("Not a Prime Number.") break else: print("A Prime Number.")
@raosajid6578
@raosajid6578 2 жыл бұрын
9 is does not satisfy your code if user enter 9 then it will give us it is prime but it is not
@rohitraj7914
@rohitraj7914 Жыл бұрын
9 jb enter krenge to num=9 ho jayega to loop 2-8 tk hi chlega. So condition is satisfying for 9 also.
@asishkumarpatro5903
@asishkumarpatro5903 9 ай бұрын
​@@rohitraj7914no brother 9 divisible by 3 so it doesn't work
@oxivrushab2573
@oxivrushab2573 Жыл бұрын
Can we use only in if condition using or like number which divides by 2,3,4,5,7,6,8,9,11 are not prime else are prime my work effectively
@impavel323
@impavel323 5 ай бұрын
a= ("Thank You Mam") Print(a)
@cnadegameplay8031
@cnadegameplay8031 7 ай бұрын
hey, check 43 as input.
@gamingstudyff9525
@gamingstudyff9525 2 жыл бұрын
Hello sir I am a school student . Sir mai athichal hacking sikhna chahta hu plz mere ko batai ki Whete to star
@AdityaThakur-cq1ov
@AdityaThakur-cq1ov Жыл бұрын
Abhi se phle where ki spelling thik kro fir agge dekhte h
@sahildash7222
@sahildash7222 Жыл бұрын
num=13 fcount=0 for f in range(1,num+1): if(num%f==0): fcount=fcount=1 if(fcount==0): print('It is a prime number') else: print('not a prime number')
@rameezraja2489
@rameezraja2489 Жыл бұрын
Simple program ko itna complex kyu bana Diya aapne ek hi condition lagega if num%==0 then print non prime number then else num%==1 then print....... whatever you want to print
@tcimert
@tcimert Жыл бұрын
Another metho num = int(input("Enter a number ")) count = 0 if num>1: for i in range(1,num+1): if (num%i) == 0: count =count+1 if count == 2: print(num,"is a prime number") else: print(num,"is not a prime number")
@asishkumarpatro5903
@asishkumarpatro5903 9 ай бұрын
Won't work 1 se sabka remainder 0 aayega
@wannabe_gamer1230
@wannabe_gamer1230 7 ай бұрын
How about 2?
@rishiraj2548
@rishiraj2548 Жыл бұрын
print("Prime Number Check") num = int(input("Enter a number to check: ")) status = "prime" if num
@Aditya_Deshmukh
@Aditya_Deshmukh Жыл бұрын
x =int(input("Enter Your Number Please: ")) if x == 2: print("A Prime Number.") else: for i in range(2,x): if x % i == 0: print("Not a Prime Number.") break else: print("A Prime Number.")
@m.abdullahm.abdullah5000
@m.abdullahm.abdullah5000 2 ай бұрын
i understand prime is difficult in python
@bobbyrajgorai695
@bobbyrajgorai695 Жыл бұрын
we can use this also; x=float(input('enter the year')) if (x+1)/2%2==0 : print ( ' the no. is prime') else: print (' the no. is not prime')
@oxivrushab2573
@oxivrushab2573 Жыл бұрын
Not effective bro👍🏻
@oxivrushab2573
@oxivrushab2573 Жыл бұрын
For 27
@ShubhamSharma-od6tf
@ShubhamSharma-od6tf 3 ай бұрын
Wrong code ❌ , as number is only being checked by dividing it by 2 .
@tcimert
@tcimert Жыл бұрын
num = int(input("Enter a number ")) if num < 2: print("Enter a number") elif num == 2: print(" 2 is a prime number") else: for i in range(2,num): if num%i ==0: print(num,"is not a prime number") break else: print(num,"is a prime number")
@shubham_gaming-i2v
@shubham_gaming-i2v Жыл бұрын
@turyachaitanya if num < 2: print("Enter a number") elif num == 2: print(" 2 is a prime number") ye vala part ka use kya tha jab 2 se num tak spicify kar rahe hai tu
@tcimert
@tcimert Жыл бұрын
@@shubham_gaming-i2v 2%2 is 0, it will say not prime, but 2 is prime. So a line is written for 2.
@dhaHu
@dhaHu Жыл бұрын
People starting in English and later changing their language 🙂but y
@saritashukla123
@saritashukla123 9 ай бұрын
This code is not right.
@VineelDikkala
@VineelDikkala 6 ай бұрын
Why bro??
@GigaChad999max
@GigaChad999max 6 ай бұрын
@@VineelDikkala because 93 is not a prime number but this code shows it is a prime number
@premgautam4957
@premgautam4957 2 жыл бұрын
Please help me sir
@sunnyyadav1298
@sunnyyadav1298 4 ай бұрын
Didi nhi ho paya tumse rehne do
@DataEngineer586
@DataEngineer586 Жыл бұрын
n= int(input("Enter any number: ")) if (n%n==0 and n%2!=0 and n>1): print("Given number is a prime ") else: print("No is not a prime ") # please let me know if this method is wrong of writing code
@ManishKumar-rd2iy
@ManishKumar-rd2iy Жыл бұрын
Your code is wrong bro
@swamantakmajumder4876
@swamantakmajumder4876 8 ай бұрын
a=int(input()) c=0 for i in range(1,a+1): if a%i==0: c=c+1 if(c==2): print("Prime number") else: print("Not prime")
@Lotus_TheGirlish
@Lotus_TheGirlish 6 ай бұрын
I did this...but this is nt working 😭annnnnn
@sumaiya_730
@sumaiya_730 5 ай бұрын
@@Lotus_TheGirlish it is working bro lol
@Lotus_TheGirlish
@Lotus_TheGirlish 4 ай бұрын
@@sumaiya_730 ok
@hrishabhbramhe1697
@hrishabhbramhe1697 7 ай бұрын
x = 4 if x ==1: print('not a prime') elif x ==2: print('prime') elif x>2: for i in range(2,x): if x%i == 0: print('not prime') break else: print('prime') break
@ShubhamSharma-od6tf
@ShubhamSharma-od6tf 3 ай бұрын
It's wrong, try 17
@shubham_gaming-i2v
@shubham_gaming-i2v Жыл бұрын
num=int (input("enter the number")) if num==1: print("not prime") for a in range(2,num): if num%a==0: print("it not a prime number") break else: print("prime number")
@SummiyaDiyar
@SummiyaDiyar 11 ай бұрын
here you miss another if condition
NumPy Full Python Course - Data Science Fundamentals
52:25
NeuralNine
Рет қаралды 98 М.
Solve any Number Pattern program in Python
20:14
Simply Coding
Рет қаралды 243 М.
ВЛОГ ДИАНА В ТУРЦИИ
1:31:22
Lady Diana VLOG
Рет қаралды 1,2 МЛН
진짜✅ 아님 가짜❌???
0:21
승비니 Seungbini
Рет қаралды 10 МЛН
Python Program to Check If the Number is Armstrong or Not?
14:37
WsCube Tech
Рет қаралды 68 М.
Solve any Star Pattern program in Python
18:44
Simply Coding
Рет қаралды 1 МЛН
10 Important Python Concepts In 20 Minutes
18:49
Indently
Рет қаралды 444 М.
Python dataclasses will save you HOURS, also featuring attrs
8:50
Learn Python in 1 hour! 🐍 (2024)
1:00:00
Bro Code
Рет қаралды 208 М.
Create a QUIZ GAME with Python 💯
9:29
Bro Code
Рет қаралды 236 М.
ВЛОГ ДИАНА В ТУРЦИИ
1:31:22
Lady Diana VLOG
Рет қаралды 1,2 МЛН