Guessing Game

This is a Guessing game where you are supposed to use a while loop. In this game, While loops can be used to cycle through your code until you get the correct number.

Linear Regression with Multiple Variables


x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] z = [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000] def SlopeD1(x, y, z, slope1, slope2, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope1 * x[i]) + (slope2 * y[i]) + yInt difference = (z[i] - predicted) * x[i] total += difference returnValue = (-2/length) * total return returnValue def SlopeD2(x, y, z, slope1, slope2, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope1 * x[i]) + (slope2 * y[i]) + yInt difference = (z[i] - predicted) * y[i] total += difference returnValue = (-2/length) * total return returnValue def InterceptD(x, y, z, slope1, slope2, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope1 * x[i]) + (slope2 *y[1]) + yInt difference = (z[i] - predicted) total += difference returnValue = (-2/length) * total return returnValue m1 = 0 m2 = 0 c = 0 l = 0.000001 iterations = 99999 for i in range(iterations): mm1 = SlopeD1(x, y, z, m1, m2 ,c) mm2 = SlopeD2(x, y, z, m1, m2 ,c) yint = InterceptD(x, y, z, m1, m2 ,c) m1 = m1 - (l * mm1) m2 = m2 - (l * mm2) c = c - (l * yint) #print(m1, m2, c) print ('(', end ='' ) print(m1, end=', ') print(m2, end=', ') print(c, end=')')

Linear Regression


x = [1, 5, 3, 4, 7, 9, 12, 13, 15, 16, 17, 4, 5, 2, 10, 23, 25] y = [5, 12, 23, 14, 17, 8, 20, 21, 25, 38, 42, 10, 13, 7, 23, 50, 55] def SlopeD(x, y, slope, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope * x[i]) + yInt difference = (y[i] - predicted) * x[i] total += difference returnValue = (-2/length) * total return returnValue def InterceptD(x, y, slope, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope * x[i]) + yInt difference = (y[i] - predicted) total += difference returnValue = (-2/length) * total return returnValue m = 0 c = 0 l = 0.000001 iterations = 99999 for i in range(iterations): slope = SlopeD(x, y, m ,c) intercept = InterceptD(x, y, m ,c) m = m - (l * slope) c = c - (l * intercept) print (m, c)

Naive Bayes Algorithm

This is a program demonstrating the Naive Bayes Algorithm. It is used to see if it will be a good day to golf.



import math #set up the predone data outlook = ['sunny','sunny','overcast','rainy','rainy','rainy','overcast','sunny', 'sunny','rainy','sunny','overcast','overcast','rainy'] temperature = ['hot','hot','hot','mild','cool','cool','cool','mild','cool', 'mild','mild','mild','hot','mild'] humidity = ['high','high','high','high','normal','normal','normal','high', 'normal','normal','normal','high','normal','high'] windy = ['false','true','false','false','false','true','true','false','false', 'false','true','true','false','true'] play = ['no','no','yes','yes','yes','no','yes','no','yes','yes','yes','yes', 'yes','no'] print("Hi welcome to the Naive Bayes Algorithm which will help calculate if it will be a good day to golf!") print("This program has some preset data that will be inputted into the algorithm""\n") #need sunny,cool,high humidity,strong wind, and play yes yescount = 0 nocount = 0 #finds the amount of days you can play golf and bad days to play golf out the the amount of days tested def findyes(): no = 0 yes = 0 for x in range(len(play)): if play[x] == 'no': no += 1 else: yes += 1 global yescount yescount += yes global nocount nocount += no print("There were", yes ,"/", len(play),"days you could golf on and","There were", no,"/",len(play),"days you couldn't golf on") findyes() yeshumid = 0 yessunny = 0 yescool = 0 yeswind = 0 ''' This is a function that helps determine the amount of humid, sunny, cool, and windy days out of the days that it was good to gold ''' def yescalculator(): highhumidity = 0 sunny = 0 cool = 0 wind = 0 for x in range(len(play)): if play[x] == 'yes': if outlook[x] == 'sunny': sunny += 1 if temperature[x] == 'cool': cool += 1 if humidity[x] == 'high': highhumidity += 1 if windy[x] == 'true': wind += 1 global yeshumid yeshumid += highhumidity global yessunny yessunny += sunny global yescool yescool += cool global yeswind yeswind += wind nohumid = 0 nosunny = 0 nocool = 0 nowind = 0 ''' This function helps determine the amount of sunny, humid, cool, a windy days bad golf days ''' def nocalculator(): sunny = 0 cool = 0 wind = 0 highhumidity = 0 for x in range(len(play)): if play[x] == 'no': if outlook[x] == 'sunny': sunny += 1 if temperature[x] == 'cool': cool += 1 if humidity[x] == 'high': highhumidity += 1 if windy[x] == 'true': wind += 1 global nohumid nohumid += highhumidity global nosunny nosunny += sunny global nocool nocool += cool global nowind nowind += wind yescalculator() nocalculator() print("\n""Probability we can play the game:") print("Probability of it being a good golf day and sunny is" ,yessunny,"/",yescount) print("Probability of it being a good golf day and cool is" ,yescool,"/",yescount) print("Probability of it being a good golf day and humid is" ,yeshumid,"/",yescount) print("Probability of it being a good golf day and windy is" ,yeswind,"/",yescount,"\n") print("Probability we cannot play a game:") print("Probability of it being a stay home day and sunny is",nosunny,"/",nocount) print("Probability of it being a stay home day and sunny is",nocool,"/",nocount) print("Probability of it being a stay home day and sunny is",nohumid,"/",nocount) print("Probability of it being a stay home day and sunny is",nowind,"/",nocount) #calculate evidence P(x) of the equation which is denominator evidences = 0 def findevidence(): evidence = (((yeshumid + nohumid)/14)*((yessunny + nosunny)/14)*((yeswind+nowind)/14)*((yescool + nocool)/14)) global evidences evidences += evidence findevidence() ''' this function multiplies all the no probabilities and yes probabilities and compares to see if it will be a good day to golf or a good day to stay home and watch a movie ''' def compare(): yesequation = (((yessunny/yescount)*(yeshumid/yescount)*(yeswind/yescount)*(yescool/yescount)*(yescount/len(play)))/evidences) noequation = (((nosunny/nocount)*(nohumid/nocount)*(nowind/nocount)*(nocool/nocount)*(nocount/len(play)))/evidences) print("\n""The probability it will be a good day is", yesequation) print("The probability it will be a bad day is", noequation) if yesequation > noequation: print("\n""There is higher probability it will be a good day for golf.","Let's go play some!") else: print("\n""There is a higher probability it will be a bad day for golf.","Lets go watch a movie!") compare()

Hangman

I made a program for Hangman, where the user is given 5 wrong letters to try to guess the random word.


import random wordbank = ["dinosaur","peanut","pencil","apple","pineapple"] separatedword = [] usedletters = [] #chooses a word from the list randomly random = random.randint(0,4) word = wordbank[random] guesses = 0 amountwrong = 5 wrong = "true" #welcomes user print("Hi welcome to Royce's Hangman Game" "\n" "Rule include: you have 5 wrong guesses", "Good Luck :)") #function to check if the user has already guessed the letter def guesscheck(userguesses): for x in range(len(usedletters)): if userguesses == usedletters[x]: print("oops you have already guessed that letter") global userguess userguess = input("\n" "Guess a letter") #separates the word up into a list by letter def separateword(): for x in range(0,len(word),1): separatedword.append(word[x]) separateword() letterleft = len(separatedword) length = len(separatedword) print("For testing purposes I'm including the random word" , word) print("The random word is", letterleft, "letters long") ''' loop to see if they can guess the word as long as the player hasn't run out of turns or has guessed it the loop will continue ''' while amountwrong != 0 and letterleft != 0: #asks user for a letter userguess = input("\n""Guess a letter") if guesses >= 1: guesscheck(userguess) #iterates through the list and checks to see if the guessed letter is in the #word for x in range(0,length,1): if userguess == separatedword[x]: print("You got the letter right!", "The word had a(n)",userguess) letterleft -= 1 wrong = "false" usedletters.append(userguess) guesses += 1 ''' uses a true or false to determine if the user has guessed wrong if true then it takes away a chance and tells the user ''' if wrong == "true": amountwrong -=1 print("oops that letter isn't in the word try again") #if not then it just continues and prints out the stats else: wrong = "true" print("You can still get" , amountwrong, "wrong" ) print("There are still", letterleft, "letters left to guess") #end of game print("\n" "You took an amount of",guesses,"guesses") if amountwrong == 0: print("Too bad you lost all your chances. Better luck next time!") else: print("Congrats! you guessed the word!", "The word was",word)

K Means Clustering

This program first assigns initial clusters to a set of data. It then takes the mean of each of these clusters and then uses them to make new clusters. If the new cluster is the same as the previous loop's cluster then the program ends.


import math import random same = "false" counter = 1 print("Hi welcome to my K Means Cluster program") #select value of K kvalue = int(input('What value of K?')) #endless loop until clusters are set while same != "true": clusterpoints = [(2,0),(2.3,0),(2.5,0),(2.7,0),(2.9,0),(2.2,0) ,(3.1,0),(3.3,0),(3.4,0),(3.6,0),(3.9,0),(3.2,0) ,(4,0),(4.5,0),(4.1,0),(4.3,0),(4.7,0),(4.5,0)] referencepoints = [] red = [] blue = [] yellow = [] #select 3 points if counter == 1: for x in range(0,kvalue,1): points = random.randint(0,15) if x == 1: red.append(clusterpoints[points]) clusterpoints.remove(clusterpoints[points]) elif x == 2: blue.append(clusterpoints[points]) clusterpoints.remove(clusterpoints[points]) else: yellow.append(clusterpoints[points]) clusterpoints.remove(clusterpoints[points]) #after the first loop it now uses the mean as a point to determine clusters if counter > 1 : red.append((findmean(previousred),0)) blue.append((findmean(previousblue),0)) yellow.append((findmean(previousyellow),0)) reddistances = [] bluedistances = [] yellowdistances = [] #function for calculating the distances def distancecalculator(color, list): for x in range(len(clusterpoints)): first = clusterpoints[x] firstvalue = first[0] secondvalue = first[1] distance = math.sqrt(((firstvalue-color[0][0])**2)+((secondvalue-color[0][1])**2)) list.append(distance) distance = 0 distancecalculator(red, reddistances) distancecalculator(blue, bluedistances) distancecalculator(yellow, yellowdistances) #assign each point to the nearest cluster placeholder1 = 0 placeholder2 = 0 placeholder3 = 0 for x in range(0,len(clusterpoints),1): placeholder1 = reddistances[x] placeholder2 = bluedistances[x] placeholder3 = yellowdistances[x] if placeholder1 < placeholder2 and placeholder1 < placeholder3: red.append(clusterpoints[x]) elif placeholder2 < placeholder3 and placeholder2 < placeholder1: blue.append(clusterpoints[x]) elif placeholder3 < placeholder2 and placeholder3 < placeholder1: yellow.append(clusterpoints[x]) #removes reference point red.pop(0) blue.pop(0) yellow.pop(0) #This is for the breaking of the loop. It checks to see if all three clusters are the same endcounter = 0 if counter > 1: if (sorted(red)==sorted(previousred)): endcounter +=1 if (sorted(red)==sorted(previousred)): endcounter +=1 if (sorted(red)==sorted(previousred)): endcounter +=1 #if all 3 clusters are same as previous loop then end code if endcounter == 3: print("\n""This is the previous clusters","\n""red",previousred,"\n""blue",previousblue,"\n""yellow",previousyellow) print("\n""This is the cluster on the next loop","\n""red",red,"\n""blue",blue,"\n""yellow",yellow) print("\n""Since they are the same, the clusters are set") print("The clusters were set in", counter, "loops") same = "true" #This is a variable that is used to keep the previous clusters previousred = red previousblue = blue previousyellow = yellow #find mean of each cluster and do the process again def findmean(list): adder = 0 for x in range(len(list)): adder += list[x][0] meanvalue = adder/len(list) return meanvalue counter+=1

Correlation Coefficient

A program that finds the correlation coefficient of two security companies(SPY and JPM) over a year and how each affect each other.


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] SPYsq=[170.66**2,170.95**2,170.70**2,169.73**2,169.18**2,169.80**2,169.31**2,169.11**2,169.61**2,168.74**2,166.38**2,165.83**2] JPMsq=[56.54**2,56.40**2,56.10**2,55.49**2,55.30**2,54.83**2,54.52**2,54.09**2,54.29**2,54.15**2,53.29**2,51.83**2] SPYxJPM=[170.66*56.54,170.95*56.40,170.70*56.10,169.73*55.49,169.18*55.30,169.80*54.83,169.31*54.52,169.11*54.09,169.61*54.29,168.74*54.15,166.38*53.29,165.83*51.83] avSPY=sum(SPY)/12 avJPM=sum(JPM)/12 avSPYsq=sum(SPYsq)/12 avJPMsq=sum(JPMsq)/12 avSPYxJPM=sum(SPYxJPM)/12 SPYvariance=avSPYsq-(avSPY*avSPY) JPMvariance=avJPMsq-(avJPM*avJPM) covariance=(avSPYxJPM)-(avSPY*avJPM) correlation_coefficient=covariance/math.sqrt(SPYvariance*JPMvariance) print('Welcome to this program, this will help you see the correlation coefficient of the sucurity companies SPY and JPM.') print ('Here is the Data for SPY:',SPY) print ('Here is the Data for JPM:',JPM) print('According to the Data the correlation coefficient is:',correlation_coefficient,'or about 93%')
Myles Brooks Jun 28

nice work

DNA to RNA to Amino Acids converter

Asks user to input length of DNA and makes a random DNA list and turns to RNA which turns to Amino Acids


import random answer=['A','T','G','C'] x=input('what length of DNA do you want') DNAlist=[] check=0 RNAlist=[] check2=0 AminoAcids=[] for y in range(int(x)): DNAlist.append(random.choice(answer)) print('DNA:',DNAlist) while int(x)>check: if (DNAlist[check]=='A'): RNAlist.append('U') elif (DNAlist[check]=='T'): RNAlist.append('A') elif (DNAlist[check]=='C'): RNAlist.append('G') elif (DNAlist[check]=='G'): RNAlist.append('C') check+=1 print('RNA:',RNAlist) RNAlist = ''.join([str(x) for x in RNAlist]) for loop_var in range((int(x)//3)): if RNAlist[check2:check2+3]=='GCA' or RNAlist[check2:check2+3]=='GCC' or RNAlist[check2:check2+3]=='GCG' or RNAlist[check2:check2+3]=='GCU': AminoAcids.append('Alanine') elif RNAlist[check2:check2+3]=='UGC' or RNAlist[check2:check2+3]=='UGU': AminoAcids.append('Cysteine') elif RNAlist[check2:check2+3]=='GAC' or RNAlist[check2:check2+3]=='GAU': AminoAcids.append('Aspartic acid') elif RNAlist[check2:check2+3]=='GAA' or RNAlist[check2:check2+3]=='GAG': AminoAcids.append('Glutamic acid') elif RNAlist[check2:check2+3]=='UUC' or RNAlist[check2:check2+3]=='UUU': AminoAcids.append('Phenylalanine') elif RNAlist[check2:check2+3]=='GGA' or RNAlist[check2:check2+3]=='GGC' or RNAlist[check2:check2+3]=='GGG' or RNAlist[check2:check2+3]=='GGU': AminoAcids.append('Glycine') elif RNAlist[check2:check2+3]=='CAC' or RNAlist[check2:check2+3]=='CAU': AminoAcids.append('Histidine') elif RNAlist[check2:check2+3]=='AUA' or RNAlist[check2:check2+3]=='AUC' or RNAlist[check2:check2+3]=='AUU': AminoAcids.append('Isoleucine') elif RNAlist[check2:check2+3]=='AAA' or RNAlist[check2:check2+3]=='AAG': AminoAcids.append('Lysine') elif RNAlist[check2:check2+3]=='UUA' or RNAlist[check2:check2+3]=='UUG' or RNAlist[check2:check2+3]=='CUA' or RNAlist[check2:check2+3]=='CUC' or RNAlist[check2:check2+3]=='CUG' or RNAlist[check2:check2+3]=='CUU': AminoAcids.append('Leucine') elif RNAlist[check2:check2+3]=='AUG': AminoAcids.append('Methionine') elif RNAlist[check2:check2+3]=='GGA' or RNAlist[check2:check2+3]=='GGC' or RNAlist[check2:check2+3]=='GGG' or RNAlist[check2:check2+3]=='GGU': AminoAcids.append('Asparagine') elif RNAlist[check2:check2+3]=='AAC' or RNAlist[check2:check2+3]=='AAU': AminoAcids.append('Proline') elif RNAlist[check2:check2+3]=='CAA' or RNAlist[check2:check2+3]=='CAG': AminoAcids.append('Glutamine') elif RNAlist[check2:check2+3]=='AGA' or RNAlist[check2:check2+3]=='AGG' or RNAlist[check2:check2+3]=='CGA' or RNAlist[check2:check2+3]=='CGC' or RNAlist[check2:check2+3]=='CGG' or RNAlist[check2:check2+3]=='CGU': AminoAcids.append('Arginine') elif RNAlist[check2:check2+3]=='AGC' or RNAlist[check2:check2+3]=='AGU' or RNAlist[check2:check2+3]=='UCA' or RNAlist[check2:check2+3]=='UCC' or RNAlist[check2:check2+3]=='UCG' or RNAlist[check2:check2+3]=='UCU': AminoAcids.append('Serine') elif RNAlist[check2:check2+3]=='ACA' or RNAlist[check2:check2+3]=='ACC' or RNAlist[check2:check2+3]=='ACG' or RNAlist[check2:check2+3]=='ACU': AminoAcids.append('Threonine') elif RNAlist[check2:check2+3]=='GUA' or RNAlist[check2:check2+3]=='GUC' or RNAlist[check2:check2+3]=='GUG' or RNAlist[check2:check2+3]=='GUU': AminoAcids.append('Valine') elif RNAlist[check2:check2+3]=='UGG': AminoAcids.append('Tryptophan') elif RNAlist[check2:check2+3]=='UAC' or RNAlist[check2:check2+3]=='UAU': AminoAcids.append('Tyrosine') check2+=3 print('AminoAcids:',AminoAcids)

Calculator

A calculator that can take an input of any number of digits and can add, subtract, multiply, and divide


x=input('what numbers would you like to add,subtract,multiply,divide?') num1=[] num2=[] z=0 operator=0 b=0 answer=0 while len(x)>z: if not(x[z]=='+' or x[z]=='-' or x[z]=='*' or x[z]=='/') and b==0: num1.append(x[z]) if not(x[z]=='+' or x[z]=='-' or x[z]=='*' or x[z]=='/') and b==1: num2.append(x[z]) elif x[z]=='+': b=1 operator='+' elif x[z]=='/': b=1 operator='/' elif x[z]=='*': b=1 operator='*' elif x[z]=='-': b=1 operator='-' z+=1 num1 = ''.join([str(x) for x in num1]) num2 = ''.join([str(x) for x in num2]) if operator=='+': answer=int(num1)+int(num2) if operator=='-': answer=int(num1)-int(num2) if operator=='*': answer=int(num1)*int(num2) if operator=='/': answer=int(num1)/int(num2) print(answer)
Elijah Jun 28

myles doesn't mean that but nice work

KNN Algorithm (K Nearest Number)

This program asks the user for a specific point and an amount of neighbors to check. It then checks these nearest points for a color and the color of the most nearest points is the color of the user's point.


import math import operator #data set data = [(3,6,"blue"), (4,7,"red"),(2,2,"purple"),(1,7,"blue"),(3,6,"red"),(2,0,"blue"),(0,9,"purple"), (0,0,"red"),(7,2,"purple"),(1,5,"red"),(0,7,"red"),(9,1,"red"),(1,1,"purple"),(2,5,"blue"), (4,0,"red"),(0,9,"blue"),(5,2,"blue"),(6,0,"red"),(2,6,"blue"),(3,3,"red"),(3,9,"purple"), (2,5,"purple"),(6,9,"blue"),(2,9,"purple"),(8,0,"red"),(7,8,"red"),(6,9,"blue"),(10,0,"purple"), (5,5,"red")] #asks user for a point and how many points close to the point xvalue = int(input("What's the x value of your point?")) yvalue = int(input("What's the y value of your point?")) kvalue = int(input("How many nearest points should there be?")) #finds all the distances and puts it into a dictionary with point and distance from user point distance = 0 distancedictionary = {} for x in range(0,len(data),1): first = data[x] firstvalue = first[0] secondvalue = first[1] distance = math.sqrt(((firstvalue-xvalue)**2)+((secondvalue-yvalue)**2)) distancedictionary[first] = distance distance = 0 #this sorts the dictionary by value sorted_distances = sorted(distancedictionary.items(), key=operator.itemgetter(1)) krange = [] colors = [] red = 0 blue = 0 purple = 0 #this puts the closest values into a list for x in range(0,kvalue,1): sortedset = sorted_distances[x] color = sortedset[0] krange.append(color[2]) print(krange) #this iterates through the list and determines the amount of colors with counters for x in range(0,len(krange),1): if(krange[x] == "red"): red = red + 1 elif(krange[x] == "blue"): blue = blue + 1 elif(krange[x] == "purple"): purple = purple + 1 print("There are " + str(red) + " red dots" ) print("There are " + str(blue) + " blue dots") print("There are " +str(purple) + " purple dots") if(red > blue and red > purple): print("Your color is red") elif(blue > red and blue > purple): print("Your color is blue") elif(purple > blue and purple > red): print("Your color is purple")

DNA to Amino Acid Converter

This program asks the user for a length of a DNA strand, it then generates the strand and converts it to RNA. After, it splits the RNA into Codons and then converts it into an Amino Acid Chain.


import random print("Welcome to Royce's DNA to Amino Acid Converter") #asks user for length of chain userlength = int(input("How long should the DNA strand be")) #generates DNA strand allamino = ["A" ,"T" , "C" , "G"] DNA = [] RNA = [] for x in range(0,userlength,1): amino = random.randint(0,3) DNA.append(allamino[amino]) print("This is the DNA Strand " + "\n" + str(DNA)) #converts to RNA for x in range(0,len(DNA),1): if DNA[x] == "A": RNA.append("U") elif DNA[x] == "T": RNA.append("A") elif DNA[x] == "C": RNA.append("G") elif DNA[x] == "G": RNA.append("C") print("This is the RNA strand " + "\n" + str(RNA)) #splits RNA into codons codons=[] amountcodons = len(RNA)/3 for x in range(0,int(amountcodons),1): holder = RNA[x] +RNA[x+1] + RNA[x+2] codons.append(holder) holder = 0 print("This is the RNA split into codons " + "\n" + str(codons)) #converts the codons into amino acids allamino = ["Lysine", "Asparagine","Isoleucine","Methionine","Threonine" ,"Arginine" ,"Serine","Stop Codon", "Tyrosine","Leucine","Phenylalanine","Cysteine","Tryptophan","Glutamine","Histidine", "Proline","Arginine","Glutamic Acid","Aspartic Acid","Valine","Alanine","Glycine"] aminoacid = [] for x in range(0,int(amountcodons),1): if codons[x] == "AAA" or codons[x] == "AAG": aminoacid.append(allamino[0]) elif codons[x] == "AAU" or codons[x] == "AAC": aminoacid.append(allamino[1]) elif codons[x] == "AUA" or codons[x] == "AUU" or codons[x] =="AUC": aminoacid.append(allamino[2]) elif codons[x] =="AUG": aminoacid.append(allamino[3]) elif codons[x] =="ACA" or codons[x] =="ACU" or codons[x]=="ACC" or codons[x]=="ACG": aminoacid.append(allamino[4]) elif codons[x] =="AGA" or codons[x] =="AGG": aminoacid.append(allamino[5]) elif codons[x] =="AGU" or codons[x] =="AGC" or codons[x] =="UCA" or codons[x] =="UCU" or codons[x] =="UCC" or codons[x] =="UCG": aminoacid.append(allamino[6]) elif codons[x] =="UAA" or codons[x] =="UAG" or codons[x] =="UGA": aminoacid.append(allamino[7]) elif codons[x] =="UAU" or codons[x] =="UAC": aminoacid.append(allamino[8]) elif codons[x] =="UUA" or codons[x] =="UUG" or codons[x] =="CUA" or codons[x] =="CUU" or codons[x] =="CUC" or codons[x] =="CUG": aminoacid.append(allamino[9]) elif codons[x] =="UUU" or codons[x] =="UUC": aminoacid.append(allamino[10]) elif codons[x] =="UGU" or codons[x] =="UGC": aminoacid.append(allamino[11]) elif codons[x] =="UGG": aminoacid.append(allamino[12]) elif codons[x] =="CAA" or codons[x] =="CAG": aminoacid.append(allamino[13]) elif codons[x] =="CAU" or codons[x] =="CAC": aminoacid.append(allamino[14]) elif codons[x] =="CCA" or codons[x] =="CCU" or codons[x] =="CCC" or codons[x] =="CCG": aminoacid.append(allamino[15]) elif codons[x] =="CGA" or codons[x] =="CGU" or codons[x] =="CGC" or codons[x] =="CGG": aminoacid.append(allamino[16]) elif codons[x] =="GAA" or codons[x] =="GAG": aminoacid.append(allamino[17]) elif codons[x] =="GAU" or codons[x] =="GAC": aminoacid.append(allamino[18]) elif codons[x] =="GUA" or codons[x] =="GUU" or codons[x] =="GUC" or codons[x] =="GUG": aminoacid.append(allamino[19]) elif codons[x] =="GCA" or codons[x] =="GCU" or codons[x] =="GCC" or codons[x] =="GCG": aminoacid.append(allamino[20]) elif codons[x] =="GGA" or codons[x] =="GGU" or codons[x] =="GGC" or codons[x] =="GGG": aminoacid.append(allamino[21]) print("This is the amino acid chain " + "\n" + str(aminoacid))

Converter for Decimal, Binary, Hexadecimal

This program converts decimal, binary, and hexadecimal


#conversion binary to decimal total = 0 power = 0 user = input("Input a binary code for me to convert to a decimal") for x in range(len(user)-1, -1, -1): if(user[x] == "1"): total = total + ((2**power)) power = power + 1 print(total) #conversion decimal to binary list = [] add = 0 decimal = input("Input a decimal for me to convert to binary") list.append(int(decimal) % 2) while int(decimal) > 1: decimal = int(decimal)/2 list.append(int(decimal) % 2) list.reverse() for x in range(0,len(list),1): print(list[x], end = ""), #function for converting the higher than 10 remainders def remaindercheck(remainder): if remainder == 10: remainder = "A" if remainder == 11: remainder = "B" if remainder == 12: remainder = "C" if remainder == 13: remainder = "D" if remainder == 14: remainder = "E" if remainder == 15: remainder = "F" return remainder #conversion decimal to hexadecimal hexalist = [] remainder = 0 hexa = input("\n" "Input a decimal for me to convert to hexadecimal") while int(hexa) > 16: remainder = int(hexa) % 16 hexa = (int(hexa)/16) remainder = remaindercheck(remainder) hexalist.append(remainder) remainder = int(hexa)%16 remainder = remaindercheck(remainder) hexalist.append(remainder) hexalist.reverse() for x in range(0,len(hexalist),1): print(hexalist[x],end ="") #binary to hexadecimal binary = input("\n" "Input a binary code for me to convert to hexadecimal") binarytotal = 0 newpower = 0 for x in range(len(binary)-1, -1, -1): if(binary[x] == "1"): binarytotal = binarytotal + ((2**newpower)) newpower = newpower + 1 converthex = [] while int(binarytotal) > 16: remainder = int(binarytotal) % 16 binarytotal = (int(binarytotal)/16) remainder = remaindercheck(remainder) converthex.append(remainder) remainder = int(binarytotal)%16 remainder = remaindercheck(remainder) converthex.append(remainder) converthex.reverse() for x in range(0,len(converthex),1): print(converthex[x],end ="") #hexadecimal to decimal total = 0 powers = 0 placeholder = 0 hexadecimal = input("\n" "Input a hexadecimal for me to convert to decimal") for x in range(len(hexadecimal)-1,-1,-1): placeholder = hexadecimal[x] if(hexadecimal[x] == "A"): placeholder = 10 if(hexadecimal[x] == "B"): placeholder = 11 if(hexadecimal[x] == "C"): placeholder = 12 if(hexadecimal[x] == "D"): placeholder = 13 if(hexadecimal[x] == "E"): placeholder = 14 if(hexadecimal[x] == "F"): placeholder = 15 total = total + (int(placeholder))*(16**powers) powers = powers + 1 print(total) #hexadecimal to binary totaled = 0 nextpower = 0 holder = 0 hexadecimaltobin = input("Input a hexadecimal for me to convert to binary") for x in range(len(hexadecimaltobin)-1,-1,-1): holder = hexadecimaltobin[x] if(hexadecimaltobin[x] == "A"): holder = 10 if(hexadecimaltobin[x] == "B"): holder = 11 if(hexadecimaltobin[x] == "C"): holder = 12 if(hexadecimaltobin[x] == "D"): holder = 13 if(hexadecimaltobin[x] == "E"): holder = 14 if(hexadecimaltobin[x] == "F"): holder = 15 totaled = totaled + (int(holder))*(16**nextpower) nextpower = nextpower + 1 listed = [] added = 0 listed.append(int(totaled) % 2) while int(totaled) > 1: totaled = int(totaled)/2 listed.append(int(totaled) % 2) listed.reverse() for x in range(0,len(listed),1): print(listed[x], end = "")
1 2 ... 4