Primer Melting Temperature

Foundational Bioinformatics PCR Conditionals Functions Formatting
Significance:

Before any PCR runs, a bench scientist has to know the melting temperature of their
primers — the temperature at which half the primer-template duplex has dissociated. Get it wrong and
the reaction either fails to amplify or amplifies the wrong thing. Two standard formulas are used
depending on primer length, and knowing which one applies is part of routine primer design in every
molecular biology lab.

Statement

Given a primer sequence, compute its melting temperature (Tm) in degrees Celsius using
the Wallace rule for short primers and the salt-adjusted formula for longer ones.

  • If the primer length is less than 14 bases, use:
    Tm = 2*(A + T) + 4*(G + C)
  • If the primer length is 14 bases or more, use:
    Tm = 64.9 + 41*(G + C - 16.4) / (A + T + G + C)

Print the result rounded to two decimal places.

Input — read from standard input
Variable Type Description
primer
line 1
str The primer sequence
4 <= len(primer) <= 40, uppercase A, C, G, T only

These variables are already read for you in the starter code on the right.

Output

str melting temperature in Celsius, formatted to exactly two decimal places

Sample Cases
Sample 1
Input
ACGTACGT
Expected Output
24.00
Eight bases, so the Wallace rule applies: 2*(2+2) + 4*(2+2) = 24.
Sample 2
Input
GCGCGCGCGCGCGCGCGC
Expected Output
68.54
Eighteen bases, so the salt-adjusted formula applies.

Submit also runs your code against 6 hidden test cases. Hidden inputs are never shown — if one fails you'll get its number and a description of the mismatch, not the data.

Constraints
  • 4 <= length(primer) <= 40
  • primer contains only uppercase A, C, G, T
  • Output must show exactly two decimal places, including trailing zeros (e.g. 12.00)
Further Reading
  • Count each base once up front rather than recounting inside the formula.
  • Use f"{tm:.2f}" in Python or sprintf("%.2f", tm) in R so both languages agree exactly.
  • Watch the branch boundary: length 13 uses the Wallace rule, length 14 uses the salt-adjusted one.

My Notes
Log in to save personal notes.
Console output will appear here when you click Run Code or Submit...
Expected: primer (str)
Next Problem
Multi-FASTA Parser