.. automodule:: Exercises Python Essentials ================= This exercise module covers the first part of the course, the introduction to Python, otherwise knoiwn as Python essentials : types, functions, loops. .. automodule:: Exercises.essentials :members: The "Name String Exercise" (first exercise in the "Strings" section) introduces some key conventions used thoughout the exercises and should be done first even if the programming concepts are familiar. Strings ------- This group of exercises explores the use of **strings**, one of the key data types of this course, since we will spend a lot of time looking at information in **text**, and generally texts will represented as Python strings. Some of these exercises put an emphasis on looking at strings as **containers**, which is what they are in Python. Name String Exercise ^^^^^^^^^^^^^^^^^^^^ In this exercise, we will do some simple things with name strings. [:download:`Download <../Exercises/essentials/strings/name_string/name_string.py>`] Please note **download** link above. All the exercises in the module will have such a download link near the beginning. This is a file that contains all the exercise content with conveniently provided blanks for you to insert your answers. The download file will be either a python source code file or a Python notebook. This is the file that will be turned in when you have completed the exercise. When the download file is a Python source file (File extension is `.py`), you can edit the file in an appropriate editor or IDE (such as the Canopy editor). It is usually more comfortable to work in an editor that allows you to run the contents of the file (all IDEs allow this). Remember to save the file when you feel the exercise is has been completed. Finally, when the download file is a Python source file (File extension is `.py`), the convention in these exercises is that it has been designed to work as a Python **script**. That is, it can be run independently of any editing program or notebook from a commandline. Here is how to do that First connect to the directory in which the source file has been saved; in this case, we will assume the file `name_string.py` has been saved in the folder/directory `Exercises`: .. code:: bash gawron$ cd Exercises gawron$ dir [or ls in Linux/Mac] ... name_string.py ... The `dir` or `ls` command lists the contents of the current directory or folder, and will confirm that the Python source file is where you think it is. Next execute the file using the Python interpreter as follows: .. code:: bash gawron$ python name_string.py [the output from the program will appear] If you wish to explore the programming state a bit (for example, when debugging), it is usually a good idea to run Python in `Interactive` mode, so that after executing the program you can check the values of variables and other relevant parts of the prorgam state. This is done as follows: .. code:: bash gawron$ python name_string.py [the output from the program will appear] >>> After the program is run, the Python interpreter prompt appears and you can type Python commands, including commands that depend on your code having been run. Now let's turn to the `name_string` exercise proper. .. automodule:: Exercises.essentials.strings.name_string.name_string :members: Poem String Exercise ^^^^^^^^^^^^^^^^^^^^ In this exercise, we will revise a poem so that it scans corectly. [:download:`Download <../Exercises/essentials/strings/poem_string/poem_string.py>`] .. automodule:: Exercises.essentials.strings.poem_string.poem_string :members: Vote String Exercise ^^^^^^^^^^^^^^^^^^^^ In this exercise, we will give democracy a boost by counting up the votes in a small town referendum.[:download:`Download <../Exercises/essentials/strings/vote_string/vote_string.py>`] .. automodule:: Exercises.essentials.strings.vote_string.vote_string :members: Caesar's Cipher Exercise ^^^^^^^^^^^^^^^^^^^^^^^^ In this exercise, we use operations on strings to implement one of the most famous codes in the history of codes, Caesar's cipher. [:download:`Download <../Exercises/essentials/strings/caesar_cypher/caesar_cypher.py>`] .. automodule:: Exercises.essentials.strings.caesar_cypher.caesar_cypher :members: Katrina Advisory Exercise ^^^^^^^^^^^^^^^^^^^^^^^^^ In this exercise, we use operations on strings to extract information about hurricanes from NOAA reports. [:download:`Download (Jupyter notebook) <../Exercises/essentials/strings/katrina_advisory/katrina_advisory.ipynb>`] You also need to download a data file for this exercise. [:download:`katrina_advisory.txt <../Exercises/essentials/strings/katrina_advisory/katrina_advisory.txt>`] .. automodule:: Exercises.essentials.strings.katrina_advisory.katrina_advisory :members: Star Data Exercise ^^^^^^^^^^^^^^^^^^ In this exercise, we will learn about the stars, specifically how to extract and print out information from a file containing astronomical data in formatted strings. [:download:`Download <../Exercises/essentials/strings/star_data/star_data.py>`] .. automodule:: Exercises.essentials.strings.star_data.star_data :members: Web Color Exercise ^^^^^^^^^^^^^^^^^^ In this exercise, we'll learn about hexadecimal color codes for HTML colors. The download file for this exercise is a Jupyter notebook. [:download:`Download <../Exercises/essentials/strings/web_colors/web_colors.ipynb>`] .. automodule:: Exercises.essentials.strings.web_colors.web_colors :members: Star Format Exercise ^^^^^^^^^^^^^^^^^^^^ In this exercise, we will learn about formating star data. This exercise takes in teh opposite direction from the previous exercise. We go from numerical data to formatted strings that would be printed out to a file. [:download:`Download <../Exercises/essentials/strings/star_format/star_format.py>`] .. automodule:: Exercises.essentials.strings.star_format.star_format :members: DNA String Exercise ^^^^^^^^^^^^^^^^^^^ In this exercise, we use operations on strings to implement one of the most important codes of all, the DNA code. [:download:`Download <../Exercises/essentials/strings/dna_string/dna_string.py>`] .. automodule:: Exercises.essentials.strings.dna_string.dna_string :members: Lists ----- This exercise group explores programming with lists. .. automodule:: Exercises.essentials.lists :members: List Operations Exercise ^^^^^^^^^^^^^^^^^^^^^^^^ This exercise provides the opportunity to experiment some more with list creation and the use of their methods. [:download:`Download <../Exercises/essentials/lists/list_operations/list_operations.py>`] .. automodule:: Exercises.essentials.lists.list_operations.list_operations :members: Managing ACME Exercise ^^^^^^^^^^^^^^^^^^^^^^ We are now (badly) managing the employees of a new startup called `ACME Corp. `_, which has locations in Taos, Phoenix, Santa Fe, and Flagstaff. This exercise is about managing information about the company in lists. [:download:`Download <../Exercises/essentials/lists/managing_acme/managing_acme.py>`] .. automodule:: Exercises.essentials.lists.managing_acme.managing_acme :members: question_one, question_two, question_three, question_four, question_five, question_six, question_seven, question_eight Sort Words Exercise ^^^^^^^^^^^^^^^^^^^ A **sorting** exercise. [:download:`Download <../Exercises/essentials/lists/sort_words/sort_words.py>`] .. automodule:: Exercises.essentials.lists.sort_words.sort_words Katrina Advisory Analysis Exercise ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ We will keep analyzing the Katrina advisory report following the exercise from the string lecture where we computed a priority alert. [:download:`Download <../Exercises/essentials/lists/katrina_adv_analyz/katrina_adv_analyz.py>`] .. automodule:: Exercises.essentials.lists.katrina_adv_analyz.katrina_adv_analyz :members: load_data, question_one, question_two, question_three, question_four Dictionaries ------------ This group of exercises explores the use of **dictionaries**, containers that associate one kind of data with another. Roman Dictionary Exercise ^^^^^^^^^^^^^^^^^^^^^^^^^ In this exercise, we use operations on dictionaries to keep track of Roman social connections. [:download:`Download <../Exercises/essentials/dictionaries/roman_dictionary/roman_dictionary.py>`] .. automodule:: Exercises.essentials.dictionaries.roman_dictionary.roman_dictionary :members: Potato Market Dictionary Exercise ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This exercise uses dictionaries to track buy and sell orders in a small market. [:download:`Download (a Jupyter notebook) <../Exercises/essentials/dictionaries/potato_market_dictionary/potato_market_dictionary.ipynb>`] .. automodule:: Exercises.essentials.dictionaries.potato_market_dictionary.potato_market_dictionary :members: DNA Dictionary Exercise ^^^^^^^^^^^^^^^^^^^^^^^ This exercise returns to the DNA data we used in the DNA strings exercise. We show how dictionaries play a natural role storing the decoding relations for DNA. [:download:`Download (a Jupyter notenook) <../Exercises/essentials/dictionaries/dna_dictionary/dna_dictionary.ipynb>`] .. automodule:: Exercises.essentials.dictionaries.dna_dictionary.dna_dictionary :members: Sets ---- This group of exercises explores the use of **sets**, containers that have no duplicates. Sets come in two flavors, mutable and immutable. The immutable flavor is called a **frozenset**. Flight Distances Exercise ^^^^^^^^^^^^^^^^^^^^^^^^^ This exercise asks you to compute distances between cities and to represent the distances in dictionary whose keys are frozensets. [:download:`Download <../Exercises/essentials/sets/flight_distances/flight_distances.py>`] .. automodule:: Exercises.essentials.sets.flight_distances.flight_distances :members: Other Essentials (functions, loops, IO) ======================================= Basic Loops ----------- This exercise group explores using **basic loops.** .. automodule:: Exercises.essentials.basic_loops :members: Filter Words Exercise ^^^^^^^^^^^^^^^^^^^^^ This exercise explores the use of loops for **filtering**. [:download:`Download <../Exercises/essentials/basic_loops/filter_words/filter_words.py>`] .. automodule:: Exercises.essentials.basic_loops.filter_words.filter_words Inventory Exercise ^^^^^^^^^^^^^^^^^^ Use loops to calculate and report the current inventory in a warehouse. [:download:`Download <../Exercises/essentials/basic_loops/inventory/inventory.py>`] .. automodule:: Exercises.essentials.basic_loops.inventory.inventory :members: DNA Translation ^^^^^^^^^^^^^^^ This is a more ambitious exercise showing how basic loops play a role in computing something meaningful, DNA sequence functions. That is, we are going to use loops to **decode** a DNA sequence and discover what protein it builds. [:download:`Download <../Exercises/essentials/basic_loops/dna_translation/dna_translation.py>`] .. automodule:: Exercises.essentials.basic_loops.dna_translation.dna_translation :members: codon_table, amino_acid_table, sequence Prime Numbers Exercise ^^^^^^^^^^^^^^^^^^^^^^ This uses basic loops to test for a simple mathematical property, whether a number is prime. [:download:`Download (Jupyter notebook) <../Exercises/essentials/basic_loops/prime_numbers/prime_numbers.ipynb>`] .. automodule:: Exercises.essentials.basic_loops.prime_numbers.prime_numbers :members: List Comprehensions ------------------- Climate data analysis (part I) Exercise ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. automodule:: Exercises.essentials.list_comprehensions.climate_data_collection.climate_data_collection :members: Filter Words Exercise ^^^^^^^^^^^^^^^^^^^^^ .. automodule:: Exercises.essentials.list_comprehensions.filter_words_list_comp.filter_words :members: Functions --------- This exercise group explores the programming idea of a **function**. Column Cipher Exercise ^^^^^^^^^^^^^^^^^^^^^^ This exercise asks you to write function to implement a **column cipher**. It will make use of slicing. [:download:`Download <../Exercises/essentials/functions/column_cypher/column_cypher.py>`] .. automodule:: Exercises.essentials.functions.column_cypher.column_cypher :members: Great Circle Exercise ^^^^^^^^^^^^^^^^^^^^^ In this exercise you compute the distance between cities using Lat/Long coordinates. [:download:`Download <../Exercises/essentials/functions/great_circle/great_circle.py>`] .. automodule:: Exercises.essentials.functions.great_circle.great_circle :members: If Statements ------------- Some *if*-statement exercises. Fizz Buzz Exercise ^^^^^^^^^^^^^^^^^^ In this exercise you use the power of `if`-statements to write a program that teaches children about division. The game is called `fizz buzz.` [:download:`Download <../Exercises/essentials/if_statements/fizz_buzz/fizz_buzz.py>`] .. automodule:: Exercises.essentials.if_statements.fizz_buzz.fizz_buzz :members: File IO ------- Some file IO exercises. ASCII Log File Exercise ^^^^^^^^^^^^^^^^^^^^^^^ .. automodule:: Exercises.essentials.file_io.ascii_log_file.ascii_log_file :members: Star Catalog Exercise ^^^^^^^^^^^^^^^^^^^^^ .. automodule:: Exercises.essentials.file_io.star_catalog.star_catalog :members: Numpy ===== .. automodule:: Exercises.numpy :members: Text ===== .. automodule:: Exercises.text :members: Regular Expressions ------------------- .. automodule:: Exercises.text.reg_ex :members: Advanced ======== .. automodule:: Exercises.advanced :members: