hw08

.py

School

University of Minnesota-Twin Cities *

*We aren’t endorsed by this school

Course

1133

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

py

Pages

3

Uploaded by MagistrateHerring966

Report
def gc_content(dna): ''' Purpose: Determine the fraction of the characters in a dna strand that are G or C Parameter(s): dna - string containing the DNA sequence characters (string) Return Value: frac - fraction of the DNA sequence that are G or C (float) ''' count = 0 for i in range(len(dna)): if dna[i] == 'C' or dna[i] == 'G': count += 1 frac = count / len(dna) return frac def complement(dna): ''' Purpose: Create a complimentary dna sequence based on the one provided Parameter(s): dna - sequence to be used as the template for the compliment sequence (string) Return Value: comp - complement sequence based off of the original dna sequence (string) ''' comp = '' for i in range(len(dna)): if dna[i] == 'A': comp += 'T' elif dna[i] == 'T': comp += 'A' elif dna[i] == 'C': comp += 'G' elif dna[i] == 'G': comp += 'C' return comp def find_urls(html): ''' Purpose: Find urls in HTML code using the href=" text to find them and add them to a list to be returned Parameter(s): html - html code to be searched for urls (string) Return Value: urls - all urls found in the HTML code, located using href=" identifier (list) ''' i = 0 urls = [] while i != -1: i = html.find('href="', i) if i != -1: i += 6 end = html.find('"',i) urls.append(html[i:end]) i = end return urls def sentiment(message):
''' Purpose: Determines whether text has a positive or negative tone. Parameters: message (str): The text to analyze Return Value: (int) The number of "positive" words in the text minus the number of "negative" words. ''' score = 0 words = message.replace('.',' ').replace(',',' ').replace('?',' ').replace(':',' ').replace('!',' ').replace('\n', ' ').replace('\t', ' ').upper().split(' ') with open('negative_words.txt') as nfile: negative = nfile.read().split() with open('positive_words.txt') as pfile: positive = pfile.read().split() for word in words: if word in positive: score += 1 print('Positive:', word) if word in negative: score -= 1 print('Negative:', word) return score if __name__ == '__main__': print(sentiment('We deny any allegations of dream intrusion.')) #Negative: DENY #Negative: ALLEGATIONS #Positive: DREAM #Negative: INTRUSION #-2 print(sentiment(''' Buzzwords Co. has easily achieved the impossible, through incredible efficiency gains and innovation.''')) #Positive: EASILY #Positive: ACHIEVED #Negative: IMPOSSIBLE #Positive: INCREDIBLE #Positive: EFFICIENCY #Positive: GAINS #Positive: INNOVATION #5 print(sentiment(''' Hello investors, Cave Johnson here. Now I know you've sunk a lot of money into the dual portal device. But I'm here to tell you we're not banging rocks together over here. We know how to make a quantum space hole. Caroline? See, portal here, portal there... Heh heh! Look at this thing go! Now, we have run into a reproducible human error problem: a lot of expensive equipment getting broken. But don't worry, Cave took care of it. Gentlemen, I give you the Long Fall Boot. Think of it as foot-based suit of armor for the Portal Device.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help