Code:
def reverse_arabic_text(text):
"""
Reverses Arabic text while preserving the order of letters and words.
Args:
text (str): The Arabic text to be reversed.
Returns:
str: The reversed Arabic text.
"""
reversed_text = ""
words = text.split()
for word in words:
reversed_word = ""
for char in word:
if '\u0600' <= char <= '\u06FF': # Check if the character is Arabic
reversed_word = char + reversed_word
else:
reversed_word += char
reversed_text = reversed_word + " " + reversed_text
return reversed_text.strip()
# Usage example
arabic_text = "مرحبا بكم في عالم البرمجة"
reversed_arabic = reverse_arabic_text(arabic_text)
print(reversed_arabic)