To print the first 10 natural numbers using the while loop can do by repeating a block of code until a specific condition is met. While the loop does iteration until a specified condition is true.
Print first 10 natural numbers using while loop in Python
Simple example code runs the loop until “i” is greater or equal to 10. Increase the “i” value on every iteration.
i = 1 while i <= 10: print(i) i += 1
Use end in print to print in single line output
i = 1 while i <= 10: print(i, end=' ') i += 1
Output: 1 2 3 4 5 6 7 8 9 10
Do comment if you have any doubts or suggestions on this Python print with the while loop topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.