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
ACGTACGT
24.00
GCGCGCGCGCGCGCGCGC
68.54
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) <= 40primercontains only uppercaseA,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 orsprintf("%.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.