seq = "GCCGGA"
for i in range(len(seq)):
if seq[i] == "G":
print("found G at position", i)
text = input("give me some text: ")
a_count = 0
for i in range(len(text)):
if text[i] == "A":
a_count += 1
print("found A", a_count, "times in your input")
We use the round
function to prettify the output. Again count_g += 1
is the same as count_g = count_g + 1
:
seq = "GCCGGA"
count_g = 0
count_c = 0
for i in range(len(seq)):
if seq[i] == "G":
count_g += 1
elif seq[i] == "C":
count_c += 1
rel_gc_content = (count_g + count_c) / len(seq) * 100.0
print("relative gc countent is", round(rel_gc_content, 2), "%")
text = "racecar"
reverted = ""
for i in range(len(text)):
reverted = text[i] + reverted
print(text, "reverted is", reverted)