Python loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Python loop

I need to print the number divisible by 17 starting from 200. How to do that with the while loop? No while loop version of mine: a=200 b=300 #or any other number supposedly more than 17 for i in range(a, b): if i%17 == 0: print(i) break;

14th Sep 2020, 11:52 AM
JSiegerheim
25 Answers
+ 2
a=200 while a: if a%17==0: print(a) break else: a+=1
14th Sep 2020, 12:09 PM
Vijay Sai Prasad Pujari
Vijay Sai Prasad Pujari - avatar
+ 11
a=200 b=300 while a<=300: if a%17==0: print(a) a+=1
14th Sep 2020, 11:58 AM
Vijay Sai Prasad Pujari
Vijay Sai Prasad Pujari - avatar
+ 3
greaaaaaaaat! it worked
14th Sep 2020, 12:10 PM
JSiegerheim
+ 3
vijay-busy a=200 while a: if a%17==0: print(a) break else: a+=1 😀 🍻 a-=1; IMHO 🙄
15th Sep 2020, 3:30 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 3
a=200 b=300 while a<=300: if a%17==0: print(a) a+=1
15th Sep 2020, 9:37 AM
Psͥycͣhͫ๏F̶
Psͥycͣhͫ๏F̶ - avatar
+ 3
Hello a=200 while a>0: if a%17==0: print (a) break
15th Sep 2020, 2:54 PM
Kanchan Dixit
Kanchan Dixit - avatar
+ 2
Z = 200+ 17-200%17 as loop z=200 while z%17: z+=1 print(z)
14th Sep 2020, 3:26 PM
Oma Falk
Oma Falk - avatar
+ 2
a=200 while a <= 300: if a%17==0: print(a) break else: a+=1
15th Sep 2020, 12:34 PM
ravi k vishnubhotla
ravi k vishnubhotla - avatar
+ 2
That's great answer ✅
16th Sep 2020, 9:21 AM
Abubakar sadiq Aliyu
+ 1
is it possible to do that without b or the range, meaning from 200 to infinity, as 300 an option that occured to me
14th Sep 2020, 12:00 PM
JSiegerheim
+ 1
300 is not in the statement
14th Sep 2020, 12:00 PM
JSiegerheim
+ 1
ok! I think I did! All this stuff is new to me) sorry for ignorance
14th Sep 2020, 12:14 PM
JSiegerheim
+ 1
n=600 if a in range(1,n): print(a)
15th Sep 2020, 10:02 AM
Adyasha Pattanayak
+ 1
x = 200 while (True): if x%17 == 0: break else: x=x+1
15th Sep 2020, 4:31 PM
Satvik Virmani
Satvik Virmani - avatar
+ 1
x = 200 l = [ ] while True: if x%17 == 0: l.append(x) else: x+=1
15th Sep 2020, 5:11 PM
Ravi Teja
Ravi Teja - avatar
+ 1
JSiegerheim a, b=200, 300 while a<b: if not a%17: print(a) break a+=1
15th Sep 2020, 10:09 PM
LastSecond959
LastSecond959 - avatar
0
a=200 while a: if a%17==0: print(a) a+=1
14th Sep 2020, 12:01 PM
Vijay Sai Prasad Pujari
Vijay Sai Prasad Pujari - avatar
0
200 to infinity
14th Sep 2020, 12:02 PM
Vijay Sai Prasad Pujari
Vijay Sai Prasad Pujari - avatar
0
maybe my question is not clear enough! the output must be 204 as it is the least number after 200 divisible by 17. i just don’t know how to write the function using while loop. thanks!
14th Sep 2020, 12:07 PM
JSiegerheim
0
the one you have sent doesn’t break at 204
14th Sep 2020, 12:07 PM
JSiegerheim