The goal of this program is to encrypt a string. The rule is that every vowel in the string should be swapped to the third vowel after the original. If the vowel is beyond the length, return to the first one and keep counting. As for the consonants, it's similar to the first rule, except that it will be swapped to the second consonant after the original one. If there's a blank space, leave it blank.
I've encountered a problem that the string index is out of range, and I can't find where the problem is. Also, is it possible that the program is able to escape the loop automatically after text[x] can no longer find any elements?
empty=''
UA="AEIOU"
UC="BCDFGHJKLMNPQRSTVWXYZ"
text=str(input())
Flag=True
x=0
while Flag:
if ord(text[x])==32:
r=' '
empty=empty+r
elif 41<=ord(text[x])<=90:
if (ord(text[x])==65 and ord(text[x])==69 and ord(text[x])==73 and ord(text[x])==79 and ord(text[x])==85):
r=0
while (ord(text[x])!=ord(UA[r])):
r=r+1
if r+3>=len(UA):
r=r-2
else:
r=r+3
empty=empty+UA[r]
x=x+1
else:
r=0
while (ord(text[x])!=ord(UC[r])):
r=r+1
if r+2>=len(UC):
r=r-19
else:
r=r+2
empty=empty+UC[r]
x=x+1
elif ord(text[x])==None:
Flag=False
print(empty)