+ 3

Can someone please help me with the exercise below?, I'm newbie, thanks

i = 2 while i < 50: if i % i == 1 and i % 1 == i: print(i) i+=1

6th Apr 2020, 12:13 AM
Ivan Maier (Navy743)
4 Answers
+ 4
Simply your code doesn't have any output because and no divided by itself will never return 1 . You may take look about and statement. Case1 Case2 Result 0 0 0 1 1 1 0 1 0 1 0 0
6th Apr 2020, 1:19 AM
Ayush Kumar
Ayush Kumar - avatar
+ 2
Ivan Maier (Navy743) You can use WHILE LOOPS to perform tasks multiple times so that you don't have to type the same thing again and again. a = 0 #I made a variable a and set it to 0. Now while it is smaller than 10, i will keep on doing something. while a < 10: #do something Got it? a = 0 while a < 10: print(a) What this would do is that it would print 0 coz a = 0 infinitely (it wouldn't stop, coz a will always remain smaller than 10 and while a < 10, keep doing tbat. So we have to increase value of a too. a = a + 1 So that now a is 1, then 2 then 3 and eventually the program will stop.
6th Apr 2020, 1:01 AM
maf
maf - avatar
+ 1
Can you please make your question more clear . I mean what you want to ask. give description for that in your que.
6th Apr 2020, 1:02 AM
Ayush Kumar
Ayush Kumar - avatar
+ 1
Ivan Maier (Navy743) a while loop can run forever, for a limited time, or never, depending upon the condition. The condition u provided in question is wrong, and while loop won't execute a thing. 2 different things: ●WHILE CONDITION: DO THIS ●WHILE CONDITION: IF CONDITION: DO THIS % means remainder. 6 % 2 means 0 coz it divides completely 5%2 is 1 coz 1 remainder is left. Look at your condtition, it says, print(i) ONLY if i % i == 1 AND i % 1 == i. i % i can never be one coz for suppose, 53 % 53 will be 0 coz 0 remainder when divided by itself, so won't print anything
6th Apr 2020, 1:08 AM
maf
maf - avatar