Translation is the third and final step of the Central Dogma: the ribosome reads mRNA three bases
at a time and chains the corresponding amino acids. Implementing the codon table by hand is how
you internalise the genetic code's redundancy — and why synonymous mutations can be silent.
Statement
Given an RNA string whose length is a multiple of 3, translate it into a protein string using the
standard genetic code. Read the RNA in non-overlapping codons from left to right, appending the
single-letter amino acid code for each.
Stop as soon as you reach a stop codon (UAA, UAG, UGA) and do not include it in the
output. Print the protein string on one line.
Input — read from standard input
| Variable | Type | Description |
|---|---|---|
rna
line 1
|
str |
The RNA sequence to translate
length is a multiple of 3, <= 1000, uppercase A, C, G, U only
|
These variables are already read for you in the starter code on the right.
Output
str the protein string in single-letter amino acid codes, stop codon excluded
Sample Cases
AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA
MAMAPRTEINSTRING
AUGUAA
M
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
length(rna)is always a multiple of 3, and at most 1000- Uppercase
A,C,G,Uonly - Translation halts at the first stop codon; the stop codon itself is not printed
Further Reading
- Build a dictionary mapping all 64 codons to their amino acid letter.
- Slice the string in steps of 3:
rna[i:i+3]foriinrange(0, len(rna), 3).
My Notes
Private to you. Saved to your account, separate from your code.
- Ctrl + Enter run · Ctrl + Shift + Enter submit