Assignment #01

Workshop 1

Classroom assignments

#01-01: Group presentations

Starting to learn python comes with a steep learning curve. The concepts might be entirely new to you, and there’s a lot of them all at once! To get you up to speed, we will divide and conquer:

Form 4 groups. Each group will work on a set of tasks and prepare a 10-minute presentation. We will listen to the presentations at the second workshop at Saturday, September 23. Please upload your presentation files to the ILIAS folder Abgaben/01_workshop.

The goal of this exercise is for you to work in-depth on the tasks assigned to your group and elicit the most important take-home messages. Everyone will have to work through all the material during the lecture break between Sept 24–Nov 3, but with your peer’s presentation to guide you this will be a lot faster and more effective!


Group 1: Variables, expressions, and statements
  1. Work through the online course Python for Everybody (PY4E) on Variables, expressions, ….
  2. Read Section 2.2.9 in the book by Linge and Langtangen (2020).


Group 2: Intro, conditional execution (part 1)
  1. Read the first half of the Introduction of the online course Python for Everybody (PY4E).
    • From the beginning up to and including Computer hardware architecture, plus the Glossary
  2. Read the Python Syntax tutorial on indentation.
  3. Work through the PY4E chapter on Conditional execution.
    • From the beginning up to and including Nested conditionals, plus the Glossary
  4. Read Sections 1.8.3–1.8.5 in the book by Linge and Langtangen (2020).


Group 3: Intro, conditional execution (part2)
  1. Read the second half of the Introduction of the online course Python for Everybody (PY4E).
    • From Understanding programming up to and including the Glossary
  2. Read the Python Syntax tutorial on indentation.
  3. Work through the PY4E chapter on Conditional execution.
    • From Catching exceptions … up to and including the Glossary
  4. Read Section 2.1 in the book by Linge and Langtangen (2020).


Group 4: Numpy arrays, strings
  1. Work through Section 2.3 in the book by Linge and Langtangen (2020).
  2. Read Sections 8.1, 8.2, 8.4, 8.5, 8.8, 8.9 in the e-book by Downey (2012).

Assignment until workshop 2 (23.09.2023)

Carefully review the course material from today’s workshop. Ensure that conda, python, and our conda environment scipro2023 are installed and properly working on your laptop. Do the exercises embedded in the slide decks, if you haven’t done so in class. Also, finalize preparing your group presentation until the next workshop!

In addition, do the following exercises until our workshop next week. No need to hand them in at this stage, but be prepared to present your code.

#01-02: conda

  1. Create a new conda environment testenv without specifying a python version for it, and also install the packages ipython and numpy into the environment. Do not yet activate it.
  2. Run conda --help in the terminal and examine the available conda commands.
  3. Run conda info --help and read the documentation.
  4. Use conda info to display a list of all environments currently installed on your computer.
    • How many environments are there?
    • Where are they installed?
  5. Activate testenv.
  6. Find out which version of python was installed in testenv. Use conda --help to find the correct command!
  7. Deactivate testenv. Make sure that no environment is activated anymore (i.e., no parentheses with an environment name are displayed before your command line).
  8. Remove testenv by running conda remove -n testenv --all.

#01-03: The solar elevation angle

Write a program and save it as .py file in the directory $SCIPRO/01_workshop/. The program should compute and plot the solar elevation angle for Sept 16, 2023 at noon true local time (i.e., tau = 0) for all latitudes from the equator to the north pole in 5\(^\circ\) intervals. Use version 3 of our second program (in the slide deck 01C_first_steps.html) to guide you. Try to execute your program in the terminal.

Learning checklist

  • I have a foundational understanding of variables, expressions, and math operations.
  • I am aware of round-off errors when working with floating point numbers.
  • I know the building blocks of programs.
  • I have a strategy for debugging code that produces errors.
  • I know that indentation plays a crucial role in coding python, and I know when and where to indent.
  • I can use boolean expressions to test and compare variables.
  • I can enchain boolean expressions using logical operators.
  • I can handle exceptions gracefully using try...except statements.
  • I can implement conditional expressions using if..elif..else statements.
  • I can use guardian patterns to make my if statements more robust.
  • I can work with numpy arrays, particularly extracting elements by indexing and slicing.
  • I can work with strings, particularly extracting elements similarly to arrays.
  • I got to know some string methods and understand the difference between functions and methods.
  • I know that I can apply methods with the dot notation.
  • I know how to create a new conda environment and install packages into it. This will be particularly useful for setting up the correct environment for other classes and projects.

References

Downey, Allen. 2012. Think Python: How to Think Like a Computer Scientist. O’Reilly Media, Inc. https://greenteapress.com/thinkpython2/html/index.html.
Linge, Svein, and Hans Petter Langtangen. 2020. Programming for Computations-Python: A Gentle Introduction to Numerical Simulations with Python 3.6. Springer Nature. https://doi.org/10.1007/978-3-319-32428-9.