basic constructions fchoose tto be straight line td on oecall trial( and try to find through experimentation some values and such that the sum of sines sn tis good approximation to the straight line gnow we shall try to automate the procedure in fwrite function that has three nested loops over values of and let each loop cover the interval oe in steps of for each combination of and the error in the approximation sn should be computed use this to findand printthe smallest error and the corresponding values of and let the program also plot and the approximation sn corresponding to the smallest error filenamefit_sines py remarks the function sn xis special case of what is called fourier series at the beginning of the th centuryjoseph fourier ( - showed that any function can be approximated analytically by sum of cosines and sines the approximation improves as the number of terms ( is increased fourier series are very important throughout science and engineering today (afinding the coefficients bn is solved much more accurately in exercise by procedure that also requires much less human and computer work(bin real applicationsf tis not known as continuous functionbut function values of tare provided for examplein digital sound applicationsmusic in cd-quality wav file is signal with , samples of the corresponding analog signal tper second exercise count occurrences of string in string in the analysis of genes one encounters many problem settings involving searching for certain combinations of letters in long string for examplewe may have string like gene 'agtcaatggaataggccaagcgaatatttgggctaccawe may traverse this stringletter by letterby the for loop for letter in gene the length of the string is given by len(gene)so an alternative traversal over an index is for in range(len(gene)letter number is reached through gene[ ]and substring from index up tobut not including jis created by gene[ :jawrite function freq(lettertextthat returns the frequency of the letter letter in the string texti the number of occurrences of letter divided by the length of text call the function to determine the frequency of and in the gene string above compute the frequency by hand too bwrite function pairs(lettertextthat counts how many times pair of the letter letter ( ggoccurs within the string text use the function to determine how many times the pair aa appears in the string gene above perform manual counting too to check the answer