Python - While

Card Puncher Data Processing


Python - (Loop|Iteration)


count = 0

if count < 5:
    print "Hello, I am an if statement and count is", count
while count < 10:
    print "Hello, I am a while and count is", count
    count += 1
loop_condition = True

while loop_condition:
    print "I am a loop"
    loop_condition = False
import random

print "Lucky Numbers! 3 numbers will be generated."
print "If one of them is a '5', you lose!"

count = 0
while count < 3:
    num = random.randint(1, 6)
    print num
    count += 1
    if num == 5:
        print "Sorry, you lose!"
    print "You win!"
    # the else block will execute anytime the loop condition is evaluated to False

Discover More
Card Puncher Data Processing
Language - Loop (For, While) - (Break, Continue)

Repeating a set of actions until a certain condition (predicate) fails is the job of programming loops; loops can take different forms, but they all satisfy this basic behavior. A loop includes: ...
Card Puncher Data Processing
Python - (Loop|Iteration)

Python - (Loop|Iteration) * * * See: Iterator Types * ...

Share this page:
Follow us:
Task Runner