Why my program was wrong even it is getting output for all answers.

t=int(input())
for i in range(t):
n=int(input())
s=input()[:n]
import re
z=[]
d=[‘m’,‘o’,‘d’,‘a’]
for i in s:
if i in d:
z.append(i)
s=’ ‘.join(z)
s=s.replace(’ ‘,’’)
if s==‘dadmom’ or s==‘momdad’:
if s==‘dadmom’:
x=re.split(‘mom’,s)
c=x[0]
print(c.capitalize())
else:
y=re.split(‘dad’,s)
d=y[0]
print(d.capitalize())
else:
if re.search(‘mom’,s):
print(‘Mom’)
elif re.search(‘dad’,s):
print(‘Dad’)
else:
print(‘Goo-Goo’)

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Also - please link to the Problem you are trying to solve :slight_smile:

Uploading: Screenshot_2022-01-23-22-01-53-40_40deb401b9ffe8e1df2f1cc5ba480b12.jpg…

In a far away Galaxy of Tilky Way, there was a planet Tarth where the sport of Tompetitive Toding was very popular. According to legends, there lived a setter known to give tricky string DP problems to beginners.

thef and thefina broke into an argument! They had a very lovely child thefi, who just uttered her first word! thef is arguing that thefi said dad , while thefina feels thefi said mom. And now it is upto us to put a stop to the argument!

Hence, given a string S denoting what thefi said, find if she said mom first or dad first or made just some random noise!

We say that thefi said mom if we can find a subsequence of (not necesarily contiguous) characters which spell out mom. Similar rule applies for when we consider her to have said dad.
If thefi said both mom and dad , then we consider the word which she said first. She is considered to have said mom first if we can find a subsequence of characters spelling out mom which ends before any subsequence spelling out dad ends. Otherwise, she is considered to have said dad first.
If she said neither mom nor dad, then she just made a random baby noise and we print Goo-Goo .

This is the question for the problem.

Input:
The first line of input contains T - The number of test cases in the file.
The first of each test case contains N , the length of string S.
The next line contains string S , denoting the noise made by Thefi!
Output:
For each test case, in a new line -

Print Mom if she said “mom” first.
Print Dad if she said “dad” first.
If she said neither “mom”, nor “dad”, print Goo-Goo

This is the format of input and output