Computer Science, asked by saran004newton, 7 months ago

explain the while statement with an example​

Answers

Answered by Anonymous
0

Answer:

Explanation:

he while statement allows you to repeatedly execute a block of statements as long as a condition is true. A while statement is an example of what is called a looping statement. A while statement can have an optional else clause.

number = 23

running = True

while running:

guess = int(raw_input('Enter an integer : '))

if guess == number:

 print 'Congratulations, you guessed it.'

 running = False # this causes the while loop to stop

elif guess < number:

 print 'No, it is a little higher than that.'

else:

 print 'No, it is a little lower than that.'

else:

print 'The while loop is over.'

# Do anything else you want to do here

print 'Done'

 

Similar questions