For -G7 programing language Teacher / Shamsa Hassan Alhassouni
Problem Solving Slow Down.. Pls Good Driver
What we will Learn today? Understand IF - else statements Use If – else syntax in python Use if – elif – else syntax in python Add comments Practical tasks
IF – ELSE Statement
IF .. else Statement Using If else statement to give two or more possible choices that a program can follow IF else Syntax
Discover more through your practical activity NO Task Completed Not Completed 1 Open the python edu 2 Select ‘the existing project named (grade7-1) 3 Click file > new > python file 4 Give the python file a name. (L7 - Name) 5 Type the following: 6 Run your program
Activity – color program Create a variable choice to get the user input If the user selected the character – a Print (“you are aggressive”) Else Print (“ you are social) if we have a word we assign “ “ for the word i.e if choice == “yes” If we have a single character we assign ‘ ‘ i.e if choice == ‘a’ If we have a number it should be written without any quotes. Important note
IF – elif – else Statement
Start IF .. elif Statement Input traffic Color If we have more than one condition we will be using a keyword for else if (elif) Is it Red Yes No Stop Is it Yellow If else Statement Yes No Wait Is it Green Yes No Go Stop
How many cases do I have in the traffic light case ?
Complete the activity Modify your car speed program If speed is more than 80 then the following message should appear “slow down.. Too fast” If speed is = 80 “good driver” If speed is lessthan 80 “you are so slow”
Activity – Modify color program You are aggressive You are social You are respectable You are lovely
Answer– Modify color program
comments
Comments are added in the program to explain what the program does. Syntax ## this program is called hello-world
How easy did find the today’s lesson in python?