直接反转字符串并 index 空格就行,如果没有空格就直接 len 🤣

Y.index(' ') if ' ' in (Y := input()[::-1]) else len(Y)