<jupyter_start><jupyter_text>Making Choices Learning Objectives  Explain the similarities and differences between tuples and lists  Write conditional statements including if, `elif`, and `else` branches.  Correctly evaluate expressions containing `and` and `or`. In our last lesson, we discovered something suspicious was going on in our inflammation data by drawing some plots. How can we use Python to automatically recognize the different features we saw, and take a different action for each? In this lesson, we’ll learn how to write code that runs only when certain conditions are true. ConditionalsWe can ask Python to take different actions, depending on a condition, with an if statement:<jupyter_code>num = 37
if num > 100:
    print('greater')
else:
    print('not greater')
print('done')<jupyter_output><empty_output><jupyter_text>The second line of this code uses the keyword `if` to tell Python that we want to make a choice. If the test that follows the `if` statement is true, the body of the `if` (i.e., the lines indented underneath it) are executed. If the test is false, the body of the `else` is executed instead. Only one or the other is ever executed. Conditional statements don’t have to include an else. If there isn’t one, Python simply does nothing if the test is false:<jupyter_code>num = 53
print('before conditional...')
if num > 100:
    print('53 is greater than 100')
print('...after conditional')<jupyter_output><empty_output><jupyter_text>We can also chain several tests together using elif, which is short for “else if”. The following Python code uses elif to print the sign of a number.<jupyter_code>num = -3

if num > 0:
    print(num, "is positive")
elif num == 0:
    print(num, "is zero")
else:
    print(num, "is negative")<jupyter_output><empty_output><jupyter_text>One important thing to notice in the code above is that we use a double equals sign == to test for equality rather than a single equals sign because the latter is used to mean assignment.We can also combine tests using `and` and `or`. `and` is only true if both parts are true:<jupyter_code>if (1 > 0) and (-1 > 0):
    print('both parts are true')
else:
    print('at least one part is false')<jupyter_output><empty_output><jupyter_text>while `or` is true if at least one part is true:<jupyter_code>if (1 < 0) or (-1 < 0):
    print('at least one test is true')<jupyter_output><empty_output><jupyter_text>Checking out DataNow that we’ve seen how conditionals work, we can use them to check for the suspicious features we saw in our inflammation data. In the first couple of plots, the maximum inflammation per day seemed to rise like a straight line, one unit per day. We can check for this inside the `for` loop we wrote with the following conditional:```pythonif data.max(axis=0)[0] == 0 and data.max(axis=0)[20] == 20:    print('Suspicious looking maxima!')```We also saw a different problem in the third dataset; the minima per day were all zero (looks like a healthy person snuck into our study). We can also check for this with an `elif` condition:```pythonelif data.min(axis=0).sum() == 0:    print('Minima add up to zero!')```And if neither of these conditions are true, we can use else to give the all-clear:```pythonelse:    print('Seems OK!')```lets test that out then!<jupyter_code>import numpy as np

data = np.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
if data.max(axis=0)[0] == 0 and data.max(axis=0)[20] == 20:
    print('Suspicious looking maxima!')
elif data.min(axis=0).sum() == 0:
    print('Minima add up to zero!')
else:
    print('Seems OK!')
data = numpy.loadtxt(fname='inflammation-03.csv', delimiter=',')
if data.max(axis=0)[0] == 0 and data.max(axis=0)[20] == 20:
    print('Suspicious looking maxima!')
elif data.min(axis=0).sum() == 0:
    print('Minima add up to zero!')
else:
    print('Seems OK!')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10303967027305512, 'fraction_numerical': 0.015455950540958269, 'mean_word_length': 4.84789156626506, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 30, 'https://': 0, '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': '308984', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1128, 'n_words': 520, 'path': '02-Python1/02-Python-1-Logic_Instructor.ipynb', 'repo_name': 'OpenAstronomy/Workshop-Lessons', 'size': '3882'}