حالت آفلاین — محتوا از حافظهٔ کش نمایش داده می‌شود
همهٔ تمرین‌ها

برعکس کردن کلمات جمله

تمرین آسان 2786 visibility link download flag

برنامه ای بنویسید که یک جمله دریافت کرده و تک تک کلمات را برعکس کرده و مجدد جمله را بدون تغییر در ترتیب کلمات چاپ کند.

input: hello amir ...
olleh rima ...
👨‍💻 11 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد

پاسخ‌ها 17

sentasce=input("enter your sentasce>>>")
li_sentasce=[]
for t in sentasce:
    li_sentasce.append(t)
mirroring=li_sentasce[: :-1]
new_mirrored_sentacse=[]
for i in mirroring:
    new_mirrored_sentacse.append(i)
print("".join(new_mirrored_sentacse))



def reverse_words(sentence):
    # جدا کردن کلمات جمله
    words = sentence.split()
    
    # برعکس کردن هر کلمه و ذخیره در لیست جدید
    reversed_words = [word[::-1] for word in words]
    
    # ترکیب کلمات برعکس‌شده به یک جمله
    reversed_sentence = " ".join(reversed_words)
    
    return reversed_sentence

ارسال جواب

جوابت را با Markdown بنویس و ثبت کن

×
بستن