Amit Dhamu

Software Engineer

Loops In Python

words = ['python', 'looks', 'like', 'it', 'could', 'be', 'fun']

# foreach
for word in words:
    print(word, len(word))

# foreach and range
for num in range(0, 5):

# while
count = 0
while (count < 9):
    print('The count is:', count)
    count = count + 1
    print('The count is 9. Finishing')

# while with input
password = ""
while password != "secret":
    password = input("Please enter the password: ")
    if password == "secret":
        print("Thank you. You have entered the correct password")
        print("Sorry the value entered in incorrect - try again")

 loops / range / while / foreach

File Operations In PythonPrevent Safari Reopening Previous Session

Show Comments

Made with by Amit Dhamu.
© MMXX. All rights reserved.