Python Forum
What exactly is wrong with my list.append function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What exactly is wrong with my list.append function?
#1
my question here
Hello. I have been practicing on my Python skills by making a little program translating DRA/RNA codons. However, while everything else works correctly thus far, it seems that my lis.append function doesn't work properly, and doesn't actually add items to my list. Can someone spot what is going on?
def analyser():
        bases=("A","T","U","G","C")
        type=0 #0=Undefined, 1=DNA, 2=RNA, 3=Hybrid DNA/RNA
        data=input("Please insert your DNA or RNA strand here:")
        print("Checking for errors...")
        #The following segment is incomplete, as it assumed that all codons are translated toaminoacids-regardless of start/end codons. Updates should change this segment to allow a more realistic spectrum of strands.
        if len(data)%3!=0:
                print("Incompatible number of bases. Please check your input and try again.")
                analyser()
        for i in range(1,len(data)):
                if data[i] not in bases:
                        print("Incorrect base input found at position",i+1,"of the strand. Please correct your input and try again.")
                        analyser()
        if "T" in data and "U" not in data:
                print("Strand classified as a DNA strand.")
                type=1
        if "U" in data and "T" not in data:
                print("Strand classified as an RNA strand.")
                type=2
        if "T" in data and "U" in data:
                print("Strand contains both U and T bases. The strand will be classified as a hybrid DNA/RNA strand, and translated accordingly.")
                type=3
        if "T" not in data and "U" not in data:
                print("Strand type not determined. The strand will be translated regardless.")
                type=0
        print("Translating strand...")
        amino=[]
        for i in range(1,len(data),3):
                if data[i+1]=="A":
                        if data[i+2]=="T" or data[i+2]=="U":
                                if data[i+3]=="G":
                                        amino.append("Methionine")
                                else:
                                        amino.append("Isoleucine")
                        if data[i+2]=="C":
                                amino.append("Threonine")
                        if data[i+2]=="A":
                                if data[i+3]=="A" or data[i+3]=="G":
                                        amino.append("Lysine")
                                else:
                                        amino.append("Asparagine")
                        if data[i+2]=="G":
                                if data[i+3]=="A" or data[i+3]=="G":
                                        amino.append("Arginine")
                                else:
                                        amino.append("Serine")
        #The rest of the aminoacids have to be added.
        print("The strand translates into a polypeptide chain with this aminoacid composition:")
        print(amino)
                                        
Reply


Messages In This Thread
What exactly is wrong with my list.append function? - by Coga19000 - Aug-24-2017, 12:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  append str to list in dataclass flash77 6 465 Mar-14-2024, 06:26 PM
Last Post: flash77
Question How to append integers from file to list? Milan 8 1,447 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,539 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  read a text file, find all integers, append to list oldtrafford 12 3,535 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  Using .append() with list vs dataframe Mark17 7 10,370 Jun-12-2022, 06:54 PM
Last Post: Mark17
  print function output wrong with strings. mposwal 5 3,112 Feb-12-2021, 09:04 AM
Last Post: DPaul
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 2,324 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  How to append to list a function output? rama27 5 6,723 Aug-24-2020, 10:53 AM
Last Post: DeaD_EyE
  Append list into list within a for loop rama27 2 2,378 Jul-21-2020, 04:49 AM
Last Post: deanhystad
  Append only adding the same list again and again viraj1123 4 2,040 Jun-17-2020, 07:26 AM
Last Post: viraj1123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020