RSLondon Software Carpentry 2020-11-25/27

General information

This collaborative document (hackmd) is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents.

:closed_book: Users are expected to follow our code of conduct.

:bookmark_tabs: The Workshop webpage contains the installations instructions for the software that we will use during the next three days.

:video_camera: Zoom links for each day will be shared via e-mail.

Guides to tools we will use

Pre-workshop Questionnaire

Sessions

Wed 25 Thu 26 Fri 27
10’00 Command line
14’00 Version control with Git Python 1/2 Python 2/2

The Unix Command line - Chris Cave-Ayland

:pencil: Notes (for everyone to add them together 😉)

:question: Questions about Unix command line

Here you can post any question you have while we are going through this document. Please, use a new bullet point for each question and sub-bullet points for their answers.

For example writing like this:

- Example question
  - [name=student_a] Example answer
  - [name=TA_1] Example answer

produces the following result:

:pencil: Feedback

Tell us at least one good thing and something we could improve by leaving feedback as post-its on the interactive board.

Version Control with Git - Iain Barrass

:pencil: Notes

Software Carpentry lesson material for GitHub Remotes.

:question: Questions about Git

:pencil: Feedback

Tell us at least one good thing and something we could improve by leaving feedback as post-its on the interactive board.

Python - day 1 - Iain Stenson

:pencil: Notes

Download python-novice-inflammation-data.zip.

:question: Questions about Python 1/2

Exercises

Exercise Session 1

You can find tips or answers to most exercises in the lesson notes.

1.

What values do the variables mass and age have after each of the following statements? Test your answer by executing the lines.

mass = 47.5
age = 122
mass = mass * 2.0
age = age - 20

2.

What does the following program print out?

first, second = 'Grace', 'Hopper'
third, fourth = second, first
print(third, fourth)

Exercise Session 2

A section of an array is called a slice. We can take slices of character strings as well:

element = 'oxygen'
print('first three characters:', element[0:3])
print('last three characters:', element[3:6])
  1. What is the value of element[:4]? What about element[4:]? Or element[:]?
  2. What is element[-1]? What is element[-2]?
  3. Given those answers, explain what element[1:-1] does.
  4. How can we rewrite the slice for getting the last three characters of element, so that it works even if we assign a different string to element? Test your solution with the following strings: carpentry, clone, hi.

Exercise Session 3

Why do all of our plots stop just short of the upper end of our graph? Can we adjust the y limit of our graph so that it looks better?

some_plot.set_ylim(min, max)

Can you create your own graph of the standard deviation using

np.std()

Exercise Session 4

1.

Python has a built-in function called range that generates a sequence of numbers. range can accept 1, 2, or 3 parameters. If one parameter is given, range generates a sequence of that length, starting at zero and incrementing by 1. For example, range(3) produces the numbers 0, 1, 2. If two parameters are given, range starts at the first and ends just before the second, incrementing by one. For example, range(2, 5) produces 2, 3, 4. If range is given 3 parameters, it starts at the first one, ends just before the second one, and increments by the third one. For example, range(3, 10, 2) produces 3, 5, 7, 9. Using range, write a loop that prints the first 3 natural numbers:

1
2
3

2.

Given the following loop, how many times is print called? 3, 4, 5, or 6 times?

word = 'oxygen'
for char in word:
    print(char)

3.

Exponentiation is built into Python and is done with **.

print(5 ** 3)  # prints 125

Can you calculate 5 to the power 3 using multiplication (*) and loops instead of the ** operator?

:pencil: Feedback

Tell us at least one good thing and something we could improve by leaving feedback as post-its on the interactive board.

Good things

Things to improve

Python - day 2 - Tom Dowrick

:pencil: Notes

Use a for-loop to convert the string “hello” into a list of letters:

string = "hello" #add your code ['h', 'e', 'l', 'l', 'o'] # To create an empty list my_list = []

Exercise 2

Plot the difference between the average inflammations reported in the first and second datasets (stored in inflammation-01.csv and inflammation-02.csv, correspondingly), i.e., the difference between the leftmost plots of the first two figures.

Don’t need to use for loops.

Exercise 3

if 4 > 5: print('A') elif 4 == 5: print('B') elif 4 < 5: print('C')

What would be printed if you run this code?

Exercise 4

Write a function that takes a string, and returns the first and last character.

string = "hello" def my_func(string): # ...... return something x = my_func(string) # x = "ho"

Exercise 5

Write a command line application that takes a string and two numbers, and outputs those two characters from the string.

e.g. hello 1 3
hl

:question: Questions about Python 2/2

:pencil: Feedback

Tell us at least one good thing and something we could improve by leaving feedback as post-its on the interactive board.

tags: swc teaching live-notes