Control Structures If Else Statement
S E S Q C E N U …consecutive steps (or groups of steps) processed one after another in the order that they arise. E A bit like reading through a cooking recipe, one line at a time.
Sometimes we want to test if one condition is true or false. For example, IF Sarah > 16, then she can learn to drive ELSE she is too young to drive
Condition? YesNo …a decision-making step. True Block False Block
In PYTHON, what is the SYNTAX for the IF statement? if : else : Name='Sydney' if len(Name)>15: print('You have a long name!') else: print('You have a short name!') An example of PYTHON IF Statement Syntax
Task 1 1)Create a program that prompts the user for their age 2)If their age is less than 14 it should produce a simple funny statement 3) If their age is greater than or equal to 14, it should produce a different statement 4) Create your program in SCRIPT mode and save it as Simple If Statement
Task 2 1)Create a program that prompts the user for their NAME and the YEAR they were born. 1)If their year is after 1999, the program should output ‘ Welcome NAME, you are a 21 st Century Child!’ 3) If their year is not after 1999, the program should output ‘ Welcome NAME, you are a 20 th Century child! ’ 4) Create your program in SCRIPT mode and save it as Simple If Statement 2
Task 3 1)Create a program that prompts the user for a PASSWORD 2)If the entered password is less than 8 characters long, it should output ‘ Password Rejected.’ 3) If the entered password is at least 8 characters long, it should output ‘ Password Accepted.’ 4) Create your program in SCRIPT mode and save it as Simple If Statement 3