#Livermore High School


Decimal to Binary to Hexadecimal (and vice versa)

I have not fully completed the hexadecimal to binary code or the hexadecimal to decimal code yet.


import math def turnToHexaNum(remainder): if(remainder == '10'): remainder = 'A' elif(remainder == '11'): remainder = 'B' elif(remainder == '12'): remainder = 'C' elif(remainder == '13'): remainder = 'D' elif(remainder == '14'): remainder = 'E' elif(remainder == '15'): remainder = 'F' return remainder def BinaryToDecimal(Binary): Binary = Binary [::-1] arrayBinary = [] index = 0 decimal = 0 for ch in Binary: array = (ch, index) arrayBinary.append(array) index += 1 for num in arrayBinary: decimal += int(num[0]) * int(2 ** num[1]) return decimal def DecimalToBinary(decimal): remainders = '' while decimal > 0: remainder = decimal % 2 decimal = decimal // 2 remainders += str(remainder) return remainders [::-1] def DecimalToHexadecimal(decimal): remainders = '' while(decimal > 16): remainder = str(decimal % 16) decimal = decimal // 16 remainder = turnToHexaNum(remainder) remainders += remainder remainder = str(decimal) remainder = turnToHexaNum(remainder) remainders += remainder return remainders [::-1] def BinaryToHexadecimal(Binary): decimal = BinaryToDecimal(Binary) return DecimalToHexadecimal(decimal) def HexadecimalToDecimal(Hexadecimal): decimal = 0 Hexadecimal = Hexadecimal [::-1] index = 0 for ch in Hexadecimal: if ch == 'A': ch = '10' elif ch == 'B': ch = '11' elif ch == 'C': ch = '12' elif ch == 'D': ch == '13' elif ch == 'E': ch == '14' elif ch == 'F': ch == '15' decimal += (input(ch)) * (16 ** index) index += 1 return decimal def HexadecimalToBinary(Hexadecimal): decimal = HexadecimalToDecimal(Hexadecimal) return DecimalToBinary(decimal) print('Binary to Decimal: ' + str(BinaryToDecimal('0000011'))) print('Decimal to Binary: ' + DecimalToBinary(224)) print('Decimal to Hexadecimal: ' + DecimalToHexadecimal(224)) print('Binary to Hexadecimal: ' + BinaryToHexadecimal('0000011')) print('Hexadecimal to Decimal: ' + HexadecimalToDecimal('E0')) print('Hexadecimal to Binary: ' + HexadecimalToBinary('E0'))

DNA Strand Maker --> RNA strand --> Codons --> Amino Acids

This is my 7th project using python, and this program creates a random DNA strand which is then converted to an RNA strand, then to codons, and finally to amino acids.


import random print ("This is a random DNA string generator.") length = int(input("Enter the length of the DNA sequence(length needs to be divisible by 3): ")) while length % 3 != 0: length = int(input("Length has to be divisible by 3. Please enter another length: ")) DNA = [] RNA = [] codons = [] aminoAcids = [] def makeDNA (): for x in range(length): num = random.randint (1,5) if num == 1: DNA.append ("A") elif num == 2: DNA.append ("C") elif num == 3: DNA.append ("G") else: DNA.append ("T") def RNAConverter (): for char in DNA: if char == 'A': RNA.append ('U') elif char == 'C': RNA.append ('G') elif char == 'G': RNA.append ('C') else: RNA.append ('A') def codonConverter(): numOfCodons = 0 for x in range(int(len(RNA) / 3)): codon = RNA[numOfCodons * 3] codon += RNA[(numOfCodons * 3) + 1] codon += RNA[(numOfCodons * 3) + 2] codons.append(codon) numOfCodons += 1 def aminoAcidMaker(): for codon in codons: if codon == 'UUU' or codon == 'UUC': aminoAcids.append('Phe') elif codon == 'UUA' or codon == 'UUG' or codon == 'CUU' or codon == 'CUC' or codon == 'CUA' or codon == 'CUG': aminoAcids.append('Leu') elif codon == 'AUU' or codon == 'AUC' or codon == 'AUA': aminoAcids.append('Ile') elif codon == 'AUG': aminoAcids.append('Met') elif codon == 'GUU' or codon == 'GUC' or codon == 'GUA' or codon == 'GUG': aminoAcids.append('Val') elif codon == 'UCU' or codon == 'UCC' or codon == 'UCA' or codon == 'UCG' or codon == 'AGU' or codon == 'AGC': aminoAcids.append('Ser') elif codon == 'CCU' or codon == 'CCC' or codon == 'CCA' or codon == 'CCG': aminoAcids.append('Pro') elif codon == 'ACU' or codon == 'ACC' or codon == 'ACA' or codon == 'ACG': aminoAcids.append('Thr') elif codon == 'GCU' or codon == 'GCC' or codon == 'GCA' or codon == 'GCG': aminoAcids.append('Ala') elif codon == 'UAU' or codon == 'UAC': aminoAcids.append('Tyr') elif codon == 'UAA' or codon == 'UAG' or codon == 'UGA': aminoAcids.append('Stop') elif codon == 'CAU' or codon == 'CAC': aminoAcids.append('His') elif codon == 'CAA' or codon == 'CAG': aminoAcids.append('Gln') elif codon == 'AAU' or codon == 'AAC': aminoAcids.append('Asn') elif codon == 'AAA' or codon == 'AAG': aminoAcids.append('Lys') elif codon == 'GAU' or codon == 'GAC': aminoAcids.append('Asp') elif codon == 'GAA' or codon == 'GAC': aminoAcids.append('Glu') elif codon == 'UGU' or codon == 'UGC': aminoAcids.append('Cys') elif codon == 'UGG': aminoAcids.append('Trp') elif codon == 'CGU' or codon == 'CGC' or codon == 'CGA' or codon == 'CGG' or codon == 'AGA' or codon == 'AGG': aminoAcids.append('Arg') elif codon == 'AGU' or codon == 'AGC': aminoAcids.append('Ser') elif codon == 'GGU' or codon == 'GGC' or codon == 'GGA' or codon == 'GGG': aminoAcids.append('Gly') makeDNA() RNAConverter() codonConverter() aminoAcidMaker() print ("The DNA strand is :", str(DNA)) print ("The DNA strand converted to RNA is :", str(RNA)) print ("The RNA strand converted to codons is :", str(codons)) print ("The codons converted to amino acids are :", str(aminoAcids))
1