Hi I would like to know how I can calculate the fraction of certain letters in a string. Like for example if I have the string "ABGTACTGASDJASBFGJAFKA" and want to calculate the fraction of A+D in that string what would I have to do? I want to do this without having to import anything and only using the built in functions of python.
A = ""
D = ""
A = string.count("A")
D = string.count("D")
print(int(A/D * 100), "%")
A/D is not a the fraction of a certain letter in the whole sting.
The following line will calculate the percentage of "A" in your string.
100.0 * ( string.count("A") / len(string) )
My suggestion, don't do both characters at once. Start with this
def fraction(string, letter):