# File: hw3_1.py # This program the GC content of a DNA string print 'Enter path to file containing DNA string:' # Ask for path to file containing DNA string # and load DNA string into memory dna = open(raw_input(), 'U').read() # Initialize counters gc_counter = 0 dna_counter = 0 # Go through the DNA string for letter in dna: if letter == 'g' or letter == 'G' \ or letter == 'c' or letter == 'C': # Everytime a G or C base pair is encountered, # update gc_counter (and also global counter) gc_counter += 1 dna_counter += 1 if letter == 'a' or letter == 'A' \ or letter == 't' or letter == 'T': # Everytime a A or T base pair is encountered, # only update the global counter dna_counter += 1 # Display result print 'The GC content of the DNA string is (in %)' print 100*(float(gc_counter) / dna_counter)