Professional Documents
Culture Documents
Discussion Forum Cs 1101 Unit 3
Discussion Forum Cs 1101 Unit 3
branches. Using elif that is an abbreviation of “else if”. Again, exactly one branch will run.
There is no limit on the number of elif statements. If there is an else clause, it must be at the
end, but there doesn’t have to be one. Each condition is checked in order. If the first is false,
the next is checked, and so on. If one of them is true, the corresponding branch runs, and the
statement ends. Even if more than one condition is true, only the first true branch runs.
(Downey.A, 2015).
Example:
if s <= 2:
print("It is enough?")
else:
print("You have too much shoes, stop spending money with it.")
Nested conditionals is when you write an if inside another if. As the outer conditional contains
two branches, the first branch contains if statement, the second branch contains another if
statement (Downey.A, 2015).
Example:
if h >= 180:
if h == "yes":
print("Cool, me too!")
else:
170
We can avoid nested conditionals by using the logical operators. simplifying nested
conditionals by combining both conditions using “and”, “or” and “not” (Downey.A, 2015).
if 10 < n: #first if
else:
Example simple:
else: