Foundations Checkpoint: Can You Read the Code?

Ten short code-reading questions across Python, R and the command line. For each one, predict what the code does before you look. Every answer was checked by running the code.

Track checkpoint ~20 min In your browser, no code

What this checks

  • You can predict what short Python, R and shell commands do.
  • You know the 0-based (Python) versus 1-based (R) difference.
  • You can handle missing values and type errors.
  • You can count reads and sequences from the command line.

Before you start

  • Finish the Level 1 basics for Python, R and the command line.
  • No notes on the first try. The point is to find out what you can recall, which is also one of the best ways to make it stick.

How this checkpoint works

Answer all ten questions. When you finish, the page shows your score. 7 of 10 counts as a pass; aim for 8 or more before moving on. Every explanation links to the lesson to review.

This is a self-check, not an exam. The answers live in the page, so it only works if you answer honestly before reading the explanation. If you score below 7, review the linked lessons, wait a day or two, then reload and try again. Coming back after a break helps you remember more than re-reading straight away.

The ten questions

Scenario questions. Pick the best answer; some wrong answers are tempting on purpose.

Python. What does this print?
seq = "TTAGC"
print(seq[3])
Python counts positions from 0, so position 3 is the fourth letter: T(0) T(1) A(2) G(3) C(4). Review: Python basics.
Python. What is in counts after this runs?
counts = {}
for base in "AACG":
    counts[base] = counts.get(base, 0) + 1
counts.get(base, 0) returns the current count, or 0 if the base has not been seen yet, then adds 1. A dictionary maps each base to its count. Review: Python basics and Python intermediate.
Python. What does this print?
genes = ["TP53", "MYC"]
genes.append("KRAS")
print(len(genes))
append adds one item to the end of the list, so it now holds three genes. len counts items in a list, not letters. Review: Python basics.
Python. What does this print?
for base in "ACG":
    print(base)
A for loop over a string visits one letter at a time, and each print starts a new line (Python tutorial). Review: Python basics.
R. What does this return?
x <- c(5, 12, 8, 20)
x[x > 10]
x > 10 makes TRUE or FALSE for each value, and using it inside the brackets keeps only the TRUE ones. This filtering pattern is everywhere in R. Review: R intermediate.
Python and R. Which pair both give the first element of a list or vector?
Python counts from 0 and R counts from 1. Mixing them up is one of the most common off-by-one bugs for people who use both languages. Review: Python basics and R basics.
R. mean(c(2, NA, 4)) returns NA. How do you get the mean of the values you do have?
R returns NA when any value is missing, so you notice. na.rm = TRUE removes missing values first. Replacing NA with 0 would wrongly pull the mean down to 2. Review: First steps in RStudio.
Command line. wc -l reads.fastq reports 4,000 lines. How many reads does the file contain?
In practice, almost every FASTQ file uses 4 lines per record: header, sequence, a + line and qualities. The format allows long lines to wrap, but modern tools do not do this. So reads = lines divided by 4 (Cock et al. 2010). Review: Command-line basics.
Command line. What does sort ids.txt | uniq | wc -l tell you?
sort puts identical lines next to each other, uniq removes adjacent repeats, and wc -l counts what is left. The pipe | passes each command's output to the next. Review: Command-line basics.
Command line. How do you count the sequences in a FASTA file?
Every FASTA record starts with a header line beginning with >. The quotes matter: without them, the shell treats > as "save output to this file", which empties genes.fasta before grep even runs. The ^ means "at the start of the line", so only header lines are counted. Counting lines does not work, because one sequence can span many lines. Review: Command-line basics.

Sources & further reading

  1. Python Software Foundation. The Python Tutorial, chapters 3 to 5. docs.python.org
  2. Cock PJ, Fields CJ, Goto N, Heuer ML, Rice PM. The Sanger FASTQ file format for sequences with quality scores, and the Solexa/Illumina FASTQ variants. Nucleic Acids Research 38: 1767-1771, 2010. (why FASTQ has four lines per read) doi:10.1093/nar/gkp1137

Last reviewed: November 2026.

Passed? Keep going

Introduction: what bioinformatics actually is →