Correlation

import math SPY = [170.66, 170.95, 170.70, 169.73, 169.18, 169.80, 169.31, 169.11, 169.61, 168.74, 166.38, 165.83] JPM = [56.54, 56.40, 56.10, 55.49, 55.30, 54.83, 54.52, 54.09, 54.29, 54.15, 53.29, 51.83] SPY2 = [] JPM2 = [] SPY_JPM = [] digit1 = 0 digit2 = 0 digit3 = 0 digit4 = 0 digit5 = 0 digit6 = 0 digit7 = 0 #1. First, every period needs to be squared for both securities. for x in range(0, len(SPY), 1): digit = SPY[x] digit = digit * digit #print(digit) SPY2.append(digit) for x in range(0, len(JPM), 1): digit = JPM[x] digit = digit * digit #print(digit) JPM2.append(digit) #2. Multiply the each period value of SPY by each period of JPM. for x in range(0, len(JPM), 1): digit = JPM[x] * SPY[x] #print(digit) SPY_JPM.append(digit) #3. Find the Average Value for each column. SPY_AVG = sum(SPY)/len(SPY) #print(SPY_AVG) JPM_AVG = sum(JPM)/len(JPM) #print(JPM_AVG) SPY2_AVG = sum(SPY2)/len(SPY2) #print(SPY2_AVG) JPM2_AVG = sum(JPM2)/len(JPM2) #print(JPM2_AVG) SPY_JPM_AVG = sum(SPY_JPM)/len(SPY_JPM) #print(SPY_JPM_AVG) #Variance SPY_Variance = SPY2_AVG - (SPY_AVG * SPY_AVG) #print(SPY_Variance) JPM_Variance = JPM2_AVG - (JPM_AVG * JPM_AVG) #print(JPM_Variance) #Covariance covariance = SPY_JPM_AVG - (SPY_AVG * JPM_AVG) #print(covariance) #CorrelationCoefficient correlationCoefficient = covariance/math.sqrt(SPY_Variance * JPM_Variance) print(correlationCoefficient)

DNA to RNA

DNA = [] aminoAcids = "" from random import randint word = "ACTGY" randomVal = randint(0,3) x = word[randomVal] for i in range(1,16): DNA.append(word[randint(0,3)]) res = [sub.replace('A', 'U') for sub in DNA] DNA = res res = [sub.replace('T', 'A') for sub in DNA] DNA = res res = [sub.replace('C', 'X') for sub in DNA] DNA = res res = [sub.replace('G', 'C') for sub in DNA] DNA = res res = [sub.replace('X', 'G') for sub in DNA] DNA = res print(DNA) print(str(DNA)) listToStr = ''.join(map(str, DNA)) print(listToStr) aminoAcidMap = ['A', 'A', 'A', 'A', 'C', 'C', 'D', 'D', 'E', 'E', 'F', 'F', 'G', 'G', 'G', 'G', 'H', 'H', 'I', 'I', 'I', 'K', 'K', 'L', 'L', 'L', 'L', 'L', 'L', 'M', 'N', 'N', 'P', 'P', 'P', 'P', 'Q', 'Q', 'R', 'R', 'R', 'R', 'R', 'R', 'S', 'S', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T', 'V', 'V', 'V', 'V', 'W', 'Y', 'Y'] RNACombo = ["GCA" ,"GCC" ,"GCU" ,"GCG" ,"UGC" ,"UGU","GAC" ,"GAU","GAG" ,"GAA","UUC" ,"UUU","GGA" ,"GGG" ,"GGC" ,"GGU","CAC" ,"CAU""AUA" ,"AUC" ,"AUU" ,"AAA" ,"AAG","UUG" ,"UUA" ,"CUA" ,"CUC" ,"CUU" ,"CUG","AUG","AAC" ,"AAU","CCC" ,"CCA" ,"CCU" ,"CCG","CAA" ,"CAG" ,"AGA" ,"AGG" ,"CGA" ,"CGC" ,"CGG" ,"CGU","AGC" ,"AGU" ,"UCA" ,"UCC" ,"UCG" ,"UCU" ,"ACA" ,"ACC" ,"ACG" ,"ACU","GUA" ,"GUC" ,"GUG" ,"GUU","UGG","UAC" ,"UAU"] for i in range(0,15,3): x = listToStr[i:i+3] print(x) MatchFound = False for y in RNACombo: if y == x: z = RNACombo.index(y) aminoAcids = aminoAcids + aminoAcidMap[z] MatchFound = True break if MatchFound == False: print("STOP!") if MatchFound == False: print("aminoAcids:" + aminoAcids + "False") print("aminoAcids:" + aminoAcids)

Set 2 exercise for python 1A

#1)Create a for loop from 1 to 1000, printing every 3rd number. for m in range(30,350,2): print(m) #2)Create a for loop from 30 to 350 printing every even number. for z in range(30,350,2): print(z) #3)Create a for loop from 200 to -200 printing multiples of 3. for x in range(-200,200,3): if x&3 == 0: print(x) #4)Create a for loop from 1 to 1000, printing only multiples of 7. for i in range(1,1000,1): if i&7 == 0: print(i) #5)Create a program which will ask for your recent exam score out of 120 and tell you what grade you got and how many more points you would have needed to get the next grade up. A - 90% and above, B- 80% to 89.9%, C- 70% to 79.99% Student_grade = int(input("What was your test score out of 120: ")) if Student_grade >= 108: print("You got the highest score! You got an A.") elif Student_grade >= 96 and Student_grade <= 108: Points_needed_1 = 108 - Student_grade print("You got a B.You needed " + str(Points_needed_1) + " point(s) to get an A.") elif Student_grade >= 84 and Student_grade <= 96: Points_needed = 96 - Student_grade print("You got a C.You needed " + str(Points_needed) + " point(s) to get an B.") #6)Ask the user to input their favorite basketball team. Print out whether it is in the Eastern or Western Conference. Warriors- Western, Lakers - Western, Celtics - Eastern, Cavaliers - Eastern fav_basketball_team = input("What is your favorite team in the NBA?") east = ['Milwaukee Bucks', 'Toronto Raptors', 'Boston Celtics', 'Miami Heat', 'Indiana Pacers', 'Philadelphia 76ers', 'Brooklyn Nets', 'Orlando Magic', 'Washington Wizards', 'Charlotte Hornets', 'Chicago Bulls', 'New York Knicks', 'Detroit Pistons', 'Atlanta Hawks', 'Cleveland Cavaliers'] west = ['Los Angeles Lakers', 'LA Clippers', 'Denver Nuggets', 'Utah Jazz', 'Oklahoma City Thunder', 'Houston Rockets', 'Dallas Mavericks', 'Memphis Grizzlies', 'Portland Trail Blazers', 'New Orleans Pelicans', 'Sacramento Kings', 'San Antonio Spurs', 'Phoenix Suns', 'Minnesota Timberwolves', 'Golden State Warriors'] if west.count(fav_basketball_team) > 0 : print("Your favorite team is in the Western conference") elif east.count(fav_basketball_team) > 0 : print("Your favorite team is in the Eastern conference") #7)Create a program which asks the user for 3 numbers representing the year, month and day e.g 1982 10 08 and then outputs in the form 8th October 1982. month = input("What month is it: ") year = input("What year is it: ") day = input("What number day in the month is it: ") day = int(day) if day <= 20: print(str(day) + 'th' + ' ' + str(month) + ' ' + str(year)) if day > 20 and day <= 31: print(str(day) + '' + ' ' + str(month) + ' ' + str(year)) #12)Create a for loop that prints all numbers from 1 to 80 except ones that are multiples of 6. for a in range(1,80,1): if i&7 == 0: print(i) #13)Create a for loop that only prints numbers from 1 to 40 that are multiples of 4. for p in range(1,40,1): if p&4 != 0: print(p) #14)Ask the user to input a number. If the number is between 0 and 9, print "Single digit". If the number is between 10 and 99, print "Double Digit". Otherwise, print "Something else" num = input("enter a number:") num = int(num) if num >= 0 or num <= 9: print("single digit") elif num >=10 or num <= 99: print("double digit") else: print("something else") #15)Ask the user to input a word. Print out whether or not it is a palindrome. my_str = input("Choose a word") my_str = my_str.casefold() rev_str = reversed(my_str) if list(my_str) == list(rev_str): print("The string is a palindrome.") else: print("The string is not a palindrome.")
1