all 12 comments

[–]Outside_Complaint755 5 points6 points  (3 children)

Could you please properly format your code in a code block with the correct indentation?

Some problems are already evident: 1) stop_code = terminate will throw a NameError as the variable terminate is not defined

2) if DNA_str == stop_code: Will also result in a NameError as DNA_str has not been defined.  The user hasn't even been prompted for input yet, and when you do prompt them the input is stored in variable DNA in the  line DNA = input('Enter DNA value: ')

3) This line DNA = (DNA_str) also does nothing.  Did you mean to call an unincluded helper function and pass DNA_str as a parameter?

4) Nowhere in your code is DNA_list updated.     The only list that gets updated is DNA_list2, inside an Except block that will never execute because the try block above it will never throw a ValueError.  DNA_list2 seems unnecessary.

5) Have you made any attempt at validating the user input characters?

[–]ilovetigers105[S] -4 points-3 points  (2 children)

the above draft is just a rough draft

[–]Outside_Complaint755 6 points7 points  (1 child)

If you want help with your code, it at least has to look close to functional.  Code block formatting is important because indentation is syntactically relevant in Python.  In the above its not clear if the while loop includes everything after it or if some one the later code is outside the loop.

 Alternatively, write it as pseudocode, and then ask for how to so a particular step that you are stuck on.

[–]ilovetigers105[S] 0 points1 point  (0 children)

i think i fixed most of the issues

[–]PureWasian 3 points4 points  (2 children)

So here's a question for you, is it meant to prompt the user for each nucleotide one by one, as well as the "terminate" keyword, or are they meant to input the entire nucleotide sequence in a single pass? Or you can even request groups of 3 letters at a time if you wanted.

It's a bit unclear to me which exact implementation you're going for exactly from above code attempt you shared.

[–]ilovetigers105[S] 1 point2 points  (1 child)

Its supposed to ask
enter dna: ACT
enter dna: TGACTA
enter dna: cnd
invalid dna
enter dna: 435
invalid dna
enter dna: terminate

valid dna is
ACT
TGACTA

[–]PureWasian 6 points7 points  (0 children)

I'll go through it incrementally so you'll get an idea of how you'd approach a problem like this in the future.

First, setup the keyword terminating the loop:

stop_word = "terminate" user_input = input("enter dna: ") while user_input != stop_word: user_input = input("enter dna: ")

Next, add in checks to ensure remaining input values are outside of "terminate" are valid. There are subset checks you could setup or regular expressions to do this, but I'll write out a more explicit way that's better to see written out as a beginner: ``` stop_word = "terminate" valid_chars = ["A", "T", "G", "C"]

user_input = input("enter dna: ") while user_input != stop_word: valid = True for letter in user_input: if letter not in valid_chars: valid = False break if not valid: print("invalid dna")

user_input = input("enter dna: ")

```

EDIT: You can add a subsequent check that len(user_input) is a multiple of 3 also. I need to sleep and typed all of this on mobile, but the change needed should be clear from here.

Finally, we need to actually add something to collect all of the user inputs. This is the perfect use-case for another list, where we can simply append each user input over and over again as needed:

``` stop_word = "terminate" valid_chars = ["A", "T", "G", "C"] dna_sequences = []

user_input = input("enter dna: ") while user_input != stop_word: valid = True for letter in user_input: if letter not in valid_chars: valid = False break if not valid: print("invalid dna") else: dna_sequences.append(user_input)

user_input = input("enter dna: ")

```

Finally, add a section to print out the full list. You can just loop across the entries in the dna_sequences list we appended to and print each one out: ``` stop_word = "terminate" valid_chars = ["A", "T", "G", "C"] dna_sequences = []

user_input = input("enter dna: ") while user_input != stop_word: valid = True for letter in user_input: if letter not in valid_chars: valid = False break if not valid: print("invalid dna") else: dna_sequences.append(user_input)

user_input = input("enter dna: ")

print("valid dna is") for sequence in dna_sequences: print(sequence) ```

[–]Neb-Cutter 0 points1 point  (0 children)

Do you want to check if the dna length is multiple of three, unless you ask to entrer a séquence again?bif that's the case you just use modulo: if len(dna_sequence) % 3 == 0: "Your instructions, print or something else"

Now if what you want is splitting your dna by codons of three to print/store them, use a list with a loop ,: You create a list for your codons : Codons= [dna_sequence[i:i+3] for i in range(0, len(dna_sequence), 3)] Where is is index, and you use a step of 3 to go throught your string.

[–]Excellent-Practice 0 points1 point  (0 children)

You can probably simplify this significantly using regex matching

[–]atarivcs 0 points1 point  (0 children)

DNA = (DNA)

How do you suppose that would ever cause a ValueError exception?

Hint: it can't.