Python: Do While Loop Real Examples

While it is one of the loops in Python. The specialty is it never be false. You already know that in my previous post I have shared For Loop in Python. The for loop can be false.

Python: Do While Loop Real Examples

I am giving here one best example:

print("Help! My computer doesn't work!")
while True:
print("Does the computer make any sounds (fans, etc.)")
choice = input(" or show any lights? (y/n):")

In the above logic, while is always true. When in input user can give 'Y/N'.

if choice == 'n': # The computer does not have power
    print (" Do not show lights")
if choice == 'y': # It is power plugged in
   print ("show lights")
So, while is always true. Based on input the while loop works. Python is having the below list of Keywords.

Pythons Reserved Words

The Python reserved words are: and, exec, not, assert, finally, or, break, for, pass, class, form, print, continue, global, raise, def, if, return, del, import, try, elif, in, while, else, is, with, except, lambda, and yield.

Also, read


Popular Posts

Hyperledger Fabric: 20 Real Interview Questions

7 AWS Interview Questions asked in Infosys, TCS

How to Fix Python Syntax Errors Quickly

Python 'getsizeof' Command the Real Purpose

Blue Prism complete tutorials download now

Python Dictionary Vs List With Examples

How to Use the ps Command in Linux

Vi Editor to Quit use Esc and Colon

5 HBase Vs. RDBMS Top Functional Differences

The Growth of Machine Learning till TensorFlow