Lecture Note
University
American Baptist CollegeCourse
CSCI 1534 | Data Analysis and VisualizationPages
3
Academic year
2023
Muthia Marhamah
Views
0
Flow Control with Desicions IF Statement If statement is a selection statement that allows more than one possible flow of control. For example: X = 2 Y = 2 if X == 2 and Y == 1 : print("Correct") ELIF Statement Elif is short for "else if" and is used when the first if statement isn't true, but you want to check for another condition. For example: x = 2 if x == 0: print("False") elif x >= 2: print("Correct") ELSE Statement The ELSE statement specifies that alternate processing is to take place when the conditions of the matching IF statement are not satisfied. For example: y = 1
if y == 2: print("False") else: print("Correct") Nested IF Statement Nested if is a decision-making statement that works similar to other decision-making statements such as if, else, if..else, etc. For example: var = 100 if var < 200: print ("Expression value is less than 200") if var == 150: print ("Which is 150") elif var == 100: print ("Which is 100") elif var == 50: print ("Which is 50") elif var < 50: print ("Expression value is less than 50") else: print ("Could not find true expression")
Compound Conditional Statement Compound statements contain (groups of) other statements; they affect or control the execution of those other statements in some way. In general, compound statements span multiple lines, although in simple incarnations a whole compound statement may be contained in one line. For example:
Flow Control with Desicions
Please or to post comments