Change the following Python code from a For loop to a While loop: | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Change the following Python code from a For loop to a While loop:

for i in range (1,10) Print(i)

14th Dec 2018, 9:18 AM
Sagar Ambastha
Sagar Ambastha - avatar
2 Answers
+ 2
You have one variable in your for loop. How is it possible to come up with two variables in your while loop... ? You've probably mistaken x as i (?). range goes from 1 (1, inclusive) to 9 (10, exclusive). The more accurate representation in while loop syntax would be: i = 1 while i < 10: print(i) i += 1
14th Dec 2018, 9:34 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
How about this.... i=o While i<9 x+=1 Print(x)
14th Dec 2018, 9:27 AM
Sagar Ambastha
Sagar Ambastha - avatar