important questions about the while loop in Python

Some important questions about the while loop in Python to practice

  • While loop execute a set a statement as long as test statement is true.
  • A relevant variable has to be declared at the beginning of the loop
while loop flow chart python

Until a specified condition is met, a block of statements will be periodically executed in a Python while loop. And the line in the programme that follows the loop is run when the condition changes to false.

The while loop is an example of an infinite loop. When a loop is iterated indefinitely, the number of times the loop is run isn’t explicitly stated beforehand.

Example 1: Python While Loop

# while loop
count = 0
while (count < 3):
count = count + 1
print(“Vista Academy Data Science Institute”)

output

Vista Academy Data Science Institute

Vista Academy Data Science Institute

Vista Academy Data Science Institute

Write a program to print table of a number entered from the user.

a=int(input(“enter number”))
i=1
while i<10:
print(a,”*”,i,”=”,a*i)
i=i+1

Create a programme that uses a while loop to determine whether an integer is prime or not.

num1 = int(input(“Enter any number : “))
k=0
if num1 == 0 or num1 == 1:
print(“Not a prime number “)
else:
i = 2
while(i<num1):
if num1 % i == 0:
k = k+1
i = i+1
if k == 0 :
print( num1,”is prime number”)
else:
print(num1, “is not prime number”)
output
Enter any number : 67
67 is prime number

10 steps to start career in data science 5 Data Analytics Projects for Beginners 5 Excel Data Analysis Functions You Need to Know 5 Things in Your Resume from Getting Your First Job in Data Science Best Data Analytics training in Dehradun Why to learn Best Data science Training in Dehradun Categories of SQL command to know for Data Analysis Data Analyst vs. Business Analyst: What’s the Difference? Data Cleaning With Python for data analytics Data Science Case Studies given by Top Data Scientists