[英]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
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. nucl_dict
定义哪些核苷酸是互补的。
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). get
尝试查找给定第一个参数作为键的值(在这种情况下, n
每个字符),如果键不存在,则使用第二个参数(在此情况下为相同字符)。
您应该将所有内容连接在一个字符串中,并在循环结束后将其打印出来。
You can use the end
parameter like print(some_var, end='')
to not print ending newline after each call. 您可以使用诸如
print(some_var, end='')
类的end
参数在每次调用后不打印结尾的换行符。 In your loop you would want to print new line, so just run without the end
parameter there. 在循环中,您将希望打印新行,因此只需在不使用
end
参数的情况下运行即可。 See print documentation . 请参阅打印文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.