1 of 13

Day 2 - Python Review Workshop

Wednesday 8B | Room 57

9/17/2025

2 of 13

Quick Review

Operators

Data Types

Loops

Learn:

input

how to comment

3 of 13

Kahoot Time!!

Get your computers out :D

4 of 13

Downloading Python:

Online python environment:

python.org/downloads/

online-python.com

5 of 13

Problem #1

The Problem

Write a Python program that takes a DNA sequence and generates its reverse complement.

Input

A string variable named dna_sequence. For example: dna_sequence = "AGTC"

Expected Output

A string representing the reverse complement of the input. For "AGTC", the output should be "GACT".

Biological Context - DNA has two complementary strands. One strand runs in the 5' to 3' direction, and the other runs in the 3' to 5' direction.

6 of 13

Problem #1 - Hints/Structure

Create an empty string to store the reverse complement.

Use a for loop to iterate through the input dna_sequence in reverse order.

Inside the loop, use an if-elif-else statement to find the complement of each base:

  • If the base is 'A', add 'T' to the new string.

  • If the base is 'T', add 'A' to the new string.

  • If the base is 'G', add 'C' to the new string.

  • If the base is 'C', add 'G' to the new string.

Print the final reverse complement string.

7 of 13

8 of 13

Problem #2

The Problem

Write a Python program that counts the occurrences of a few specific amino acids in a protein sequence.

Input

A string variable named protein_sequence. For example: protein_sequence = "MVLSPADKTN". You will also be looking for the counts of the amino acids 'M', 'V', and 'A'.

Expected Output

A list of integers representing the counts of each specified amino acid. For "MVLSPADKTN", the output should be [1, 1, 1] for 'M', 'V', and 'A' respectively.

9 of 13

Problem #2 - Hints/Structure

Create a list with three elements, all initialized to zero, to store the counts for 'M', 'V', and 'A'.

Use a for loop to iterate through each character in the protein_sequence string.

Inside the loop, use if-elif-else statements to check for 'M', 'V', and 'A'.

  • If the amino acid is 'M', increment the first element of your list by 1.

  • Else if the amino acid is 'V', increment the second element of your list by 1.

  • Else if the amino acid is 'A', increment the third element of your list by 1.

Print the final list of counts.

10 of 13

11 of 13

Problem #3

The Problem

Write a Python program that finds all the starting positions of a specific short DNA sequence (a "restriction site") within a larger DNA sequence.

Input

Two string variables: dna_sequence (the larger sequence) and restriction_site (the shorter sequence).

Example: dna_sequence = "GAATTCGGATCC", restriction_site = "GAATTC"

Expected Output

A list of integers representing the starting indices of the restriction site within the DNA sequence. For the example above, the output should be [0]. If restriction_site = "GGATCC", the output should be [6].

12 of 13

Problem #3 - Hints/Structure

Create an empty list to store the indices.

Determine the lengths of both the dna_sequence and the restriction_site.

Use a for loop with the range() function to iterate through the dna_sequence from the beginning to the point where a match is still possible.

Inside the loop, use list slicing to extract a segment of the dna_sequence of the same length as the restriction_site.

Use an if statement and the == operator to check if this segment is equal to the restriction_site.

If there's a match, add the current index to your list of indices.

Print the final list of indices.

13 of 13