C.Cat
C.Cat

Reputation: 37

How to print horizontally instead of vertically?

I wrote a script that is supposed to print an answer to a specific input horizontally.

For example if the input is:

TTACTGGCAT

It should print:

TTACTGGCAT
AATGACCGTA

My code:

x = 0
n = input("Insert DNA seqence: ")
print(n.upper())
while x < len(n):
  if 'T' in n[x]:
    print('A')
  if 'G' in n[x]:
    print('C')
  if 'C' in n[x]:
    print('G')
  if 'A' in n[x]:
    print('T')
  x = x + 1

Upvotes: 0

Views: 1028

Answers (3)

tayfun
tayfun

Reputation: 3135

You can use the end parameter like print(some_var, end='') to not print ending newline after each call. In your loop you would want to print new line, so just run without the end parameter there. See print documentation.

Upvotes: 0

yinnonsanders
yinnonsanders

Reputation: 1871

I assume you want to do something like this:

nucl_dict = {'A':'T', 'T':'A', 'C':'G', 'G':'C'}

n = input("Insert DNA seqence: ").upper()
print(n)
print(''.join(nucl_dict.get(nucl, nucl) for nucl in n))

nucl_dict defines which nucleotides are complementary.

This joins the characters for the corresponding nucleotides into a string and prints the result.

If the character is not a valid nucleotide, the character is simply added without a change to the complementary string. get tries to find the value given the first argument as a key (in this case each character in n) and if the key does not exist uses the second argument (in this case the same character).

Upvotes: 1

exe
exe

Reputation: 107

You should concat everything in a string and after the loops end print it.

Upvotes: 0

Related Questions