replacing certain characters with others, and translating strings
Author |
Message |
rprezi
|
Posted: Mon Nov 27, 2017 9:32 am Post subject: replacing certain characters with others, and translating strings |
|
|
What is it you are trying to achieve?
I am trying to make it so if a person, for instance, inputs a DNA strand, such as GTA,ACC,GCG
My "DNA-RNA translator will output the corresponding RNA strand (in this instance, GUA,ACC,GCG)
Essentially, I'd like for the user's input to come out the same, except with all Ts being translated to Us.
I'm very new to coding, and Turing seems like a good place to start learning.
Is there some command I can use to solve this problem?
As a side note, i'm also looking to translate RNA strands into amino acid names,
which would be a similar problem, for instance an RNA input of GUA,ACC,GCG would output "valine,threonine,alanine"
How could I program the translation of specific 3 letter combinations into amino acids?
Here is my code I have written so far, for reference
I know there is probably an easier way to write it, but this is what I have.
Thanks so much,
Rory
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
var DNAstrand : string
put "Hello! Thanks for trying my the DNA Translator."
put "Any time you're ready, input the DNA sequence of nucleotides."
put "Input the sequence, placing a comma inbetween each group of 3 bases."
put "example: TAG,GTA,GCG,GAG,GAT,CCA"
loop
get DNAstrand
put "The DNA sequence you inputed is: ", DNAstrand
put "Is this correct or incorrect?"
var answer1 : string
get answer1
if answer1="incorrect" then
put "Oops, please input the correct DNA sequence."
end if
if answer1="correct" then
put "Okay, the corrosponding RNA sequence is..."
end if
exit when answer1="correct"
end loop
|
Please specify what version of Turing you are using
Turing 4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TokenHerbz
|
Posted: Tue Dec 05, 2017 10:54 pm Post subject: RE:replacing certain characters with others, and translating strings |
|
|
you want to look up case statements and heres an example.
code: |
var str : string := "B"
case str of
label "A" : put "XXX"
label "B" : put "YYY"
label "C" : put "ZZZ"
end case
|
also head over to the walkthrough and check out string manipulation, thats where you'll find your answer.
and for your first question, just look through the indexes of the string for the pattern you wish to identify then rebuild that string to use.
look up index for ideas http://compsci.ca/holtsoft/doc/
code: |
var name: string := "Dog"
var rename: string := ""
for c: 1 .. length(name)
if name(c) = "o" then
rename += "ra"
else
rename += name(c)
end if
end for
put rename
|
code: |
var namer : string := "Catfood"
if index(namer,"Cat") not= 0 then
put "Is this cat food or dog food?"
else
%%How do we change that name to mean what it should
end if
|
|
|
|
|
|
|
|
|