<jupyter_start><jupyter_text>[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/bwrsandman/learningpython/master?filepath=02-Conditional-Statements.ipynb) Conditional Statements  ReviewConditional statements are used to control execution. They are comprised of one or more clauses and a body. ClauseThe first clause must be and is the only one started by an `if` keyword. Another `if` clause marks the beginning of a new and logically separate statement.The `elif` and `else` clause accompany the `if` clause but cannot be used without it.The `else` cannot be used more than once per conditional statment and is the last clause of a conditional statement.A clause line is terminated by the `:` character.Clauses of a statement are run in order, only one clause will be satisfied.If two clauses of the same statement can evaluate to true, only the first will run.A conditional statment has an **expression** which is reduced to a boolean variable. Only`if` and `elif` can have an expression BodyFollowing an clause is a body. A clause must have a body follow it on the following line.A body is incremented by 4 spaces (first character which is not a space on each line must be preceeded by 4 spaces more than number the spaces preceeding the clause).The statements in a body are only executed if their clause is satisfied.A clause body has its own [scope](https://en.wikipedia.org/wiki/Scope_(computer_science%29). Example```python A one clause conditional statementif 1 == 1:   "if" is the keyword, "1 == 1" is the expression which evaluates to True    print("one equals one")     A two clause conditional statementif x == 1:   "if" is the keyword, "x == 1" is the expression    print("value of x equals one")else:   "else" is the keyword, there is no expression    print("value of x can equal anything but one")     A many clause conditional statementif x == 1:   "if" is the keyword, "x == 1" is the expression    print("value of x equals one")elif x == 1:   "elif" is the keyword, "x == 1" is the expression    print("This can never be run since the first clause would execute")elif x == 2:   "elif" is the keyword, "x == 2" is the expression    print("value of x equals two")elif x == 3:   "elif" is the keyword, "x == 3" is the expression    print("value of x equals three")else:   "else" is the keyword, there is no expression    print("value of x can equal anything but one to three")     Multiple clauses in different conditional statementif 2 > 1:   "if" is the keyword, "2 > 1" is the expression which evaluates to True    print("two is larger than one")if 1 > 1:   The clause is satisfied and runs because it is a separate from above    print("one is larger than one")```  Reading ExerciseIn your own words explain what is happening in the following code snippets.For each line, what does python do, which clause is satisfied, what would make each clause besatisfied?Which part is the clause, which part is the body, what is the expression?What does the expression evaluate to (`True` or `False`)Is the current line run based on the value of the expression.  1. [Tautology](https://en.wikipedia.org/wiki/Tautology_(logic%29) and [Contradiction](https://en.wikipedia.org/wiki/Contradiction) (a)Prediction:(Double click here and enter your prediction before running the next cell)<jupyter_code>if True:
    print("This is known as a tautology")<jupyter_output><empty_output><jupyter_text>1. [Tautology](https://en.wikipedia.org/wiki/Tautology_(logic%29) and [Contradiction](https://en.wikipedia.org/wiki/Contradiction) (b)Prediction:(Double click here and enter your prediction before running the next cell)<jupyter_code>if False:
    print("This is known as a contradiction")<jupyter_output><empty_output><jupyter_text>2. ExpressionsPrediction:(Double click here and enter your prediction before running the next cell)<jupyter_code>a = 1 == 1
b = 0 > 5

c = a and b
d = a or b

e = c and d
f = c or d

g = not a
h = not b

i = g and h
j = g or h

# Outputting the values and their types to Out[ ]
print("""
    a is %s
    b is %s
    
    c is %s
    d is %s
    
    e is %s
    f is %s
    
    g is %s
    h is %s
    
    i is %s
    j is %s
""" % (a, b, c, d, e, f, g, h, i, j)
)<jupyter_output><empty_output><jupyter_text>3. Multiple clausesPrediction:(Double click here and enter your prediction before running the next cell)<jupyter_code>x = 0.5

if x > 0.5:
    print("Greater than 0.5")
elif x >= 0.5:
    print("Greater or equal to 0.5")
elif x >= 0.75:
    print("Greater or equal to 0.75")
else:
    print("Another value")
    
if x > 0.25:
    print("Greater than 0.25")
if x > 0.4:
    print("Greater than 0.4")
elif x < 0.75:
    print("Smaller than 0.75")<jupyter_output><empty_output><jupyter_text>4. Complex expressionsPrediction:(Double click here and enter your prediction before running the next cell)<jupyter_code>x = 0.5
y = 10
z = -9

# First statment
if x > 0.5:
    print("x is greater than 0.5")
elif x == 0.5 and y > 18:
    print("x is 0.5 and y is greater than 18")
elif -10 < z < 8:
    print("z is between -10 and 8")
else:
    print("None of the clauses have evaluated to True")
    
# Second statment
if x > 0.25 and (y > 15 or z < 0):
    print("Second statement succeeds on first clause")
else:
    print("Second statement fails on first clause")
    
# Third statment
if x > 0.25 or (y > 15 and z < 0):
    print("Third statement succeeds on first clause")
else:
    print("Third statement fails on first clause")
    
# Fourth statment
if x > 0.25 and not (y > 15 or z < 0):
    print("Fourth statement succeeds on first clause")
else:
    print("Fourth statement fails on first clause")<jupyter_output><empty_output><jupyter_text>Writing ExerciseIn the following cells, write code which implements what the comments ask.Re-read the code in the same way as the Reading exerciseto catch any errors and to predict how the code will be executed.Run the code by pressing the run button from the toolbar whilethe cell is selected or go to (Cell|Run Cells) with the cellselected.<jupyter_code># 1.
# Declare a variable and assign a bool value to it
# Create a two clause (if and else) statement for which
# the if expression is the value of the variable

# Declare bool

# Two clause statament
# 2.
# Declare two variables and assign different int values to them
# Create a single clause statment and print a message if the
# first variable is larger than the second
# 3.
a = 0.5
b = 0.2
c = 0.5

# For the provided variables print a message only if
# a is larger than b or c


# 4
a = 0.5
b = 0.2
c = 0.5

# For the provided variables print a message only if
# a is larger than 0.5 or b is smaller than 0.25
# but if b does not equal c, then this overrides the previous test<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0874575269611464, 'fraction_numerical': 0.019796129413502735, 'mean_word_length': 3.821937321937322, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 42, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '320091', 'license': 'MIT', 'n_tokens_mistral': 2130, 'n_tokens_neox': 1973, 'n_words': 983, 'path': '02-Conditional-Statements.ipynb', 'repo_name': 'bwrsandman/learningpython', 'size': '6769'}