I hope I am not doing your school work for you. I see an answer has already been posted using .sub, but you asked for only for loops to be used
def clean(text):
cleaned_text=""
for i in range(0, len(text)):
if text[i] == "a" or text[i] == "g" or text[i] == "c" or text[i] == "t":
cleaned_text=cleaned_text+text[i]
else:
cleaned_text=cleaned_text+"n"
return cleaned_text
print(clean("agct7ttczttctgactgcaacgggcaatatgtctctxtgtggattaaaaaaagagtgtcygatagcagcttctgaactggttacctgcc"))
# returns agctnttcnttctgactgcaacgggcaatatgtctctntgtggattaaaaaaagagtgtcngatagcagcttctgaactggttacctgcc