Problem p02664 (python)

Fixed submission:
import sys
t=list(input())
for i in range(len(t)):
    if t[i]=="?":
        if len(t)==1:
            print("D")
            sys.exit()
        else:
            if i==0:
                if t[1]=="D":
                    t[0]="P"
                else:
                    t[0]="D"
            elif i==len(t)-1:
                t[i]="D"
            else:
                if t[i-1]=="P":
                    t[i]="D"
                elif t[i+1]=="D":
                    t[i]="P"
                elif t[i+1]=="?":
                    t[i]="P"
                    t[i+1]="D"
                else:
                    t[i]="D"
print("".join(t))

Buggy submission (verdict: Runtime Error):
t=list(input())
for i in range(len(t)):
    if t[i]=="?":
        if i==0:
            if t[1]=="D":
                t[0]="P"
            else:
                t[0]="D"
        elif i==len(t)-1:
            t[i]="D"
        else:
            if t[i-1]=="P":
                t[i]="D"
            elif t[i+1]=="D":
                t[i]="P"
            elif t[i+1]=="?":
                t[i]="P"
                t[i+1]="D"
            else:
                t[i]="D"
print("".join(t))

Buggy submission (verdict: Runtime Error):
t=list(input())
for i in range(len(t)):
    if t[i]=="?":
        if i==0:
            if t[1]=="D":
                t[0]="P"
            else:
                t[0]="D"
        elif i==len(t)-1:
            t[i]="D"
        else:
            if t[i-1]=="P":
                t[i]="D"
            elif t[i+1]=="D":
                t[i]="P"
            elif t[i+1]=="?":
                t[i]="P"
                t[i+1]="D"

Buggy submission (verdict: Runtime Error):
t=list(input())
for i in range(len(t)):
    if t[i]=="?":
        if i==0:
            if t[1]=="D":
                t[0]="P"
            else:
                t[0]="D"
        elif i==len(t)-1:
            t[i]="D"
        else:
            if t[i-1]=="P":
                t[i]="D"
            elif t[i+1]=="D":
                t[i]="P"
            elif t[i+1]=="?":
              t[i]="P"
              t[i+1]="D"
            else:
                t[i]="D"
print("".join(t))

Buggy submission (verdict: Runtime Error):
t=list(input())
for i in range(len(t)):
    if t[i]=="?":
        if i==0:
            if t[1]=="D":
                t[0]="P"
            else:
                t[0]="D"
        elif i==len(t)-1:
            t[i]="D"
        else:
            if t[i-1]=="P":
                t[i]="D"
            elif t[i+1]=="D":
                t[i]="P"
            elif t[i+1]=="?":
              t[i]="P"
              t[i+1]="D"
            else:
                t[i]="D"
print("".join(t))

Buggy submission (verdict: Runtime Error):
t=list(input())
for i in range(len(t)):
    if t[i]=="?":
        if i==0:
            if t[1]=="D":
                t[0]="P"
            else:
                t[0]="D"
        elif i==len(t)-1:
            t[i]="D"
        else:
            if t[i-1]=="P":
                t[i]="D"
            elif t[i+1]=="D":
                t[i]="P"
            elif t[i+1]=="?":
              t[i]="P"
              t[i+1]="D"
            else:
                t[i]="D"
print("".join(t))