User Tools

Site Tools


Practice Exercises in Unix and Python

Exercise 1

1. Create a new directory called Exercises in your Desktop directory using mkdir.

2. Change into the Exercises directory using cd.

3. Using echo, add a 12-nt DNA sequence to a file called seq.txt (use >> to redirect output to a file).

4. Identify the reverse of the sequence using rev <seq.txt (the < is commonly used to read in an input file).

5. Assign the reversed sequence to a variable.

6. Identify the complement of the reversed sequence (i.e. the reverse complement) using tr. Print the result to the seq.txt file without overwriting the contents (i.e. use >>).

Exercise 2

1. Use wc to identify the number of lines, words, and characters in the seq.txt file from exercise 1.

2. Use more or less to examine the contents of seq.txt in the terminal.

2. Use wc to identify just the number of lines in the seq.txt file from exercise 1 (google search what wc option to use).

Exercise 3

1. Make a new directory called PythonScripts in the Exercises directory using mkdir.

2. Open a new document in TextWrangler and save it as in the PythonScripts directory.

3. Write a Python script that creates a favorites profile for the user. The script should prompt the user for their name and some of their favorite things to do, such as their favorite place to eat, favorite outdoor spot, favorite hobby, favorit subject, etc. The script should print the profile to the terminal.

4. Determine the default version of Python on your computer using python --version. Is the default Python 3? If not, how can you invoke Python 3?

5. Run the script from step 3.

Exercise 4

Write a bash script that creates a favorites profile for the user (i.e. just like in exercise 3 but using bash instead of Python).

Exercise 5

Write a python script that calculates the area of a circle with radius n, where n can be any value. The script should print the result along with a brief description (e.g. “A circle with radius 5 has an area of 78.5.”).

Exercise 6

Write a script that prompts the user for two sequences, concatenates them and assigns the value to a new variable, and prints the variable within a user friendly message.

Exercise 7

Write a script that prompts the user for a sequence (allow both DNA and RNA sequences) and identifies whether the sequence contains a start codon (ATG or AUG).

Exercise 8

Write a script that prompts the user for the width of a gel tray and then determines the number of samples that can be loaded on the gel. Assume there are two possible trays that can accomodate a comb containing either 15 or 30 wells:

Tray 1: 5 cm wide (15 well comb)

Tray 2: 10 cm wide (30 well comb)

assignments/practiceproblems.txt · Last modified: 2017/09/25 10:50 by dokuroot