Program to print counting from 1 to 10 using while loop in Python.
Write a program to print counting from 1 to 10 using while loop in Python.
In this program we want to print numbers from 1 to 10. For this we have to start a loop from 1 and end at 10. Now you know for such task we always use a loops. You can use any loop that you want but we are using while loop here.
I have fully explained What is loops ? What is While loop ? and What is for loop ?
If you don't know what is loops and what is while loop or for loop. Then you have to learn about loops first. Otherwise you will not understand such programs.
[ if don't know about loops and while loop then click here to learn more about Loops and While loop in Python ]
[ if don't know about for loop then click here to learn more about For loop in Python ]
Now we have to create a Algorithm to Write this program. Let's create Algorithm.
Algorithm :
step 02: Create a variable 'count'
Explanation :
The step 01 simply says start your algorithm or solution.
The step 02 simply says that create a variable named as count ( here your variable name can be anything not mandatory to have you variable name same as I shown here ) . this variable we will use as a counter.
[ if you don't know how to create variables then click here to learn more about Variables in Python ]
The step 03 says simply initialize your counter variable to 1 that is count = 1.
The step 04 says that write a while loop and write a condition ( count <= 10 ) . And then simply check that condition is it true or false. If condition is false then directly jump on step no 08 that is stop. Or if condition is true then simply execute the while block.
[ if you don't know how to use while loop then click here to learn more about While loop in Python ]
The step 05 says that in while block simply print the value of counter variable that is count in this case.
The step 06 says that in while block increment your counter by one that is count = count + 1.
The step 07 says that goto step 04 and start again from there.
The step 08 says that your problem has solved so stop.
Now write a Program according to this algorithm.
Program :
Output :
Sample input and output
If you have any doubts in this post then please ask me in comment section below. I will try to solve it.
If you like these post and you have learned something from this then share this post with your friends and family.
Keep learning always.....!!! 😇😇😇