<jupyter_start><jupyter_text>Lesson 3: Conditionals In our work, we often want to our programs to be make decisions based on what's going on at the time.  Like most other programming languages, python supports conditional statements.  The way in which we make decisions in our code based on conditions is through the `if` statement.<jupyter_code>water_temperature = -1 # degrees celsius
if water_temperature > 100:
    print('Boiling!')
if water_temperature > 100:
    print('Boiling!')
else:
    print('Not boiling!')
water_temperature = -5
if water_temperature > 100:
    print('Boiling!')
elif water_temperature > 0:
    print('Liquid!')
else:
    print('Solid!')<jupyter_output>Solid!<jupyter_text>Note that conditions are demarcated using indentation.  This is a contentious property of python, but is implemented primarily because it makes code much easier to read.  Note also that the indentation level can be almost any combination of whitespace characters (tabs and spaces), but elements of the same indentation block must use the same type of indentation.  Because it gets confusing to use multiple types, the python style guide strongly recommends using 4 spaces to indent, which is the default in the jupyter notebook for example.  This is sometimes more difficult to toggle in text editors, but most of them have online resources for setting up your text editor to use tabs and indentation in a way that conforms to python's style.  Booleans<jupyter_code>print(3 < 2)
type(3 < 2)<jupyter_output><empty_output><jupyter_text>What is truth?<jupyter_code>bool(5)
bool("beauty")
bool([])
bool({})
bool(0)
bool(None)<jupyter_output><empty_output><jupyter_text>Be very careful with this!  Python's "falsy" functionality makes code fun to write and easier to read, but can cause problems.  For example, many people will put a simple if statement as a conditional on whether the variable is stored as a falsy value (e. g. None).  Part of the reason we're mentioning this today is that this is often the case in codes that use a lot of serialization like pymatgen.<jupyter_code>temperature = 0 # store the temperature as a number if you want it to do something
if temperature:
    print("Temperature is", temperature)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06533333333333333, 'fraction_numerical': 0.009333333333333334, 'mean_word_length': 5.201101928374656, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '85822', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 644, 'n_tokens_neox': 605, 'n_words': 299, 'path': 'lessons/python_primer/3 - Conditionals.ipynb', 'repo_name': 'srshivani/workshop', 'size': '2250'}