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 common NumPy functions that are useful for data analysis: 10 common use cases for SQL in data analytics 10 commonly used Matplotlib commands for data analytics 10 different between SQL and No SQL 10 important of data analytics for society 10 steps that show how data analytics is changing the banking industry: 10 steps to learn SQL for Data Analytics 10 steps to start career in data science 10 WAYS AGRICULTURE IS TRANSFORMED BY DATA ANALYTICS 10 ways data analytics can be used in addressing climate change: