Computing GC Content

Foundational Bioinformatics GC Content DNA Statistics
Significance:

GC content correlates with gene density, melting temperature and genome stability, and it varies
systematically between organisms — which makes it a standard first-pass discriminator in
metagenomics and a required input to PCR primer design. It's also a practical lesson in
floating-point output formatting.

Statement

Given a DNA string, compute the percentage of its bases that are G or C.

Print the percentage rounded to exactly two decimal places (for example 60.92).

Your answer is compared numerically with a tolerance of 0.01, so small formatting differences
between Python and R are accepted.

Input — read from standard input
Variable Type Description
s
line 1
str The DNA sequence to measure
1 <= len(s) <= 1000, uppercase A, C, G, T only

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

Output

float the GC percentage, rounded to 2 decimal places

Sample Cases
Sample 1
Input
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGACTGGGAACCTGCGGGCAGTAGGTGGAAT
Expected Output
60.92
53 of the 87 bases are G or C.
Sample 2
Input
AAAA
Expected Output
0.00
No G or C at all, so the answer is 0.00.

Submit also runs your code against 4 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
  • 1 <= length(s) <= 1000
  • Uppercase A, C, G, T only — so the denominator is always length(s)
Further Reading
  • Count G and C, divide by the total length, multiply by 100.
  • Python: f"{value:.2f}". R: sprintf("%.2f", value).

My Notes
Log in to save personal notes.
Console output will appear here when you click Run Code or Submit...
Expected: s (str)
Next Problem
Finding a Motif in DNA