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

خلاصه کننده متن

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

تابعی بنویسید که یک متن دریافت کند و درصورتی که متن طولانی تر از 100 کاراکتر بود، 100 کاراکتر اول آن را به همراه «...» برگرداند. در غیر این صورت کل متن را بدون تغییر برگرداند.

👨‍💻 4 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد

پاسخ‌ها 41

def truncate_text(text):
    # بررسی طول متن
    if len(text) > 100:
        return text[:100] + '...'
    else:
        return text

# مثال استفاده
input_text = input("لطفاً یک متن وارد کنید: ")
result = truncate_text(input_text)
print(result)
string txt = "New settings for your Search services\r\nSearch services have new settings to manage history and personalised recommendations that reflect your prior Web & App Activity preferences. Media (such as your images and audio) from your interactions will now also be saved in your history. You can make changes to your settings at any time.";

static void Text(string txt1)
{
    if (txt1.Length > 100)
    {
        Console.WriteLine(txt1.Substring(0, 100) + "...");
    }
    else
    {
        Console.WriteLine("the txt length is smaller 100 character");
    }
}

Text(txt);
#include <iostream>

using namespace std ;
string text_summary(string text) {
    text.erase(99) ;
    return(text + "...") ;
}

int main() {

    string txt ;
    cout << "Text : " ;
    cin >> txt ;
    cout << endl << text_summary(txt) << endl;
    return (0) ;
}

ارسال جواب

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

×
بستن