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
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGACTGGGAACCTGCGGGCAGTAGGTGGAAT
60.92
AAAA
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,Tonly — so the denominator is alwayslength(s)
Further Reading
- Count
GandC, divide by the total length, multiply by 100. - Python:
f"{value:.2f}". R:sprintf("%.2f", value).
My Notes
Private to you. Saved to your account, separate from your code.
- Ctrl + Enter run · Ctrl + Shift + Enter submit