Mar-21-2021, 07:59 PM
Hi
the exercise is the following:
Write a program to determine the mass in dalton of a protein. You can use the given dictionary with the masses (in Dalton) of the individual amino acids.
aa_mass = {
'A': 71.03711, 'G': 57.02146, 'M': 131.04049, 'S': 87.03203,
'C': 103.00919, 'H': 137.05891, 'N': 114.04293, 'T': 101.04768,
'D': 115.02694, 'I': 113.08406, 'P': 97.05276, 'V': 99.06841,
'E': 129.04259, 'K': 128.09496, 'Q': 128.05858, 'W': 186.07931,
'F': 147.06841, 'L': 113.08406, 'R': 156.10111, 'Y': 163.06333
}
Input
The first line contains the name (ID) of a protein. The subsequenct lines the amino acid sequence of a protein (60 characters at a time). The sequence ends with an empty line.
Output
A single line with a string: Protein #### has a mass of ####.## Da.
I don't know how the string (amino_acid) that the user writes in the program can be attached to the keys in the dictionary and then added up. The following code is what i already have: I know I have to use a for loop to go trough the dictionary but I don't know how the characters of the string amino_acid are compatible with the characters of the dictionary and added up.
the exercise is the following:
Write a program to determine the mass in dalton of a protein. You can use the given dictionary with the masses (in Dalton) of the individual amino acids.
aa_mass = {
'A': 71.03711, 'G': 57.02146, 'M': 131.04049, 'S': 87.03203,
'C': 103.00919, 'H': 137.05891, 'N': 114.04293, 'T': 101.04768,
'D': 115.02694, 'I': 113.08406, 'P': 97.05276, 'V': 99.06841,
'E': 129.04259, 'K': 128.09496, 'Q': 128.05858, 'W': 186.07931,
'F': 147.06841, 'L': 113.08406, 'R': 156.10111, 'Y': 163.06333
}
Input
The first line contains the name (ID) of a protein. The subsequenct lines the amino acid sequence of a protein (60 characters at a time). The sequence ends with an empty line.
Output
A single line with a string: Protein #### has a mass of ####.## Da.
I don't know how the string (amino_acid) that the user writes in the program can be attached to the keys in the dictionary and then added up. The following code is what i already have: I know I have to use a for loop to go trough the dictionary but I don't know how the characters of the string amino_acid are compatible with the characters of the dictionary and added up.
aa_mass = { 'A': 71.03711, 'G': 57.02146, 'M': 131.04049, 'S': 87.03203, 'C': 103.00919, 'H': 137.05891, 'N': 114.04293, 'T': 101.04768, 'D': 115.02694, 'I': 113.08406, 'P': 97.05276, 'V': 99.06841, 'E': 129.04259, 'K': 128.09496, 'Q': 128.05858, 'W': 186.07931, 'F': 147.06841, 'L': 113.08406, 'R': 156.10111, 'Y': 163.06333 } gen_id = str(input()) amino_acid= str(input()) for i in aa_mass: mass=sum(aa_mass[amino_acid]) print("Protein {} has a mass of {:.2f} Da.".format(gen_id, mass))```Thank you in advance.