First example is made very complex. This code will be simple. n=int(input("Enter number: ")) for i in range(2,n): flag=True for j in range(2,i): if i%j==0: flag=False break if flag: print(i) It could be made even simpler by using else block to the inner for loop, thereby eliminating the need for a Flag variable.
@nandarajan3842 жыл бұрын
Thank you.
@alexioscarlos772711 ай бұрын
I think this code is wrong bcoz n==2 then it would make flag false which is not true
@MUTHU_KRISHNAN_K7 ай бұрын
@@alexioscarlos7727for n==2 , nothing should be printed, right?since there is no prime number lesser than 2.
@TEJASWAnama03 ай бұрын
I think you forgot to mention the end=' ' in the program according to above same output
@smokyvibesКүн бұрын
much better if you check until root(i) since after thats its just gonna be multiple of them.
@avenumadhav35683 жыл бұрын
#1: 1:50 #2: 7:45 #3: 12:30 #4: 17:00
@tanmaymalviya5312 Жыл бұрын
I understand this is tutorial still they should show him type while explaining what's the logic, instead of directly taking us to the screen with already typed code
@aryangarg7359 Жыл бұрын
thats the whole dissapointment actually, there are many a times they have missed explaining important things like flag where to use when to use , just teaching like a novel story.
@rockstrsameer173 жыл бұрын
Coming soon to iit
@Adityakumar-pn7yq3 ай бұрын
this my code sample example num= int(input()) prime= 0 for i in range(2, num): for j in range(1, i): if j!= 1 and i%j == 0: break if j== i-1: print(i, end= " ")
@rituparnodhar62652 жыл бұрын
20:17 in test case 5 , we don't have input -1 in the statement but in the code You have given.
@RohitRajSharma-kh6iu3 ай бұрын
I think that is a printing mistake in the statements
@ManishKumar-qr4hb7 ай бұрын
I don't know why.... but i feel this lecture little harder
@selvamselvam79602 жыл бұрын
What is the use of flag function true false anyone let me explain plz
@aryangarg7359 Жыл бұрын
thats the whole dissapointment actually, there are many a times they have missed explaining important things like flag where to use when to use , just teaching like a novel story.
@MUTHU_KRISHNAN_K7 ай бұрын
I believe,by now,you would have no doubt on this topic.but,it may help someone else:😊 Reason for flag It's actually a more professional way, maybe,I don't know.its job is to hold 'false' if the number is not prime and to possess 'true' if the number is prime. It's usage can be completely eliminated,by using 'print' statement directly under 'else' condition 🙂👍
@054_nirajkumar33 жыл бұрын
थैंक्यू
@sayanghosh69963 жыл бұрын
for these conditions a do-while statement is better suited. shame that python doesnt have it though 😔
@MUTHU_KRISHNAN_K7 ай бұрын
Is it sir?😮 I am on the initial weeks and not aware of this. Btw,you may know me from Linux course Jan 2024 term.electronic systems😀
@sayanghosh69963 жыл бұрын
Optimal playback speed for this video: 4x 😂 (for me)
@TheUnknownU3 жыл бұрын
#find all prime numbers less than entered number num = int(input('Enter the number: ')) if(num>2): print(2,end=" ") for i in range(3, num): if i % 2 != 0: print(i, end = " ", sep = "-")