While Loops

while loops - not equal to

set default value before loop

'not equal to' symbol

password = " "

while password != "iamthebest":

          password = input("What is the password? ") 

colon required

must indent (tab key)

indented lines will be repeated until the while command is not true

What is the password? hello

What is the password? let me in

What is the password? idk

What is the password? iamthebest

Press F5 to run program:

While loops - equal to

set value before loop

'equal to' symbol

happy = "no"

while happy == "no":

          q1 = input("What is your name? ")

          q2 = input("What is your age? ") 

          q3 = input("What is your height? ") 

          happy = input("Are you happy with your answers?" )

loop repeats if happy is still 'no'

What is your name? Steve

What is your age? 20

What is your height? 6"1'

Are you happy with your answers? no

What is your name? Steve

What is your age? 21

What is your height? 6"1

Are you happy with your answers? yes

Press F5 to run program:

© CSNewbs 2020