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

برش متن

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

برنامه ای بنویسید که یک متن از ورودی دریافت کند و همانند مثال زیر، از اول تا اولین نقطه آن متن را چاپ کند


Enter: my name is amirhossein. i live in tehran.
my name is amirhossein
👨‍💻 1 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد

پاسخ‌ها 58

# Get user input for the sentence
I = input("Enter your sentence: ")
# Find the position of the first period in the sentence
P = I.find('.') 
# Check if a period was found
if P != -1:
    # Print the substring from the start of the sentence up to the period
    print(I[:P])
else:
    print("There is no period in the sentence.")
# دریافت جمله
Text = input("Enter your text =")
# پیدا کردن اولین نقطه
search_Point = Text.find('.')
# بازگرداندن متن از ابتدا تا اولین نقطه
print(Text[:search_Point])
#برش متن

#گرفتن متن ورودی
t= input("Enter your text : ")#text

#پیدا کردن اولین نقطه
s=t.find('.')#search

#چاپ متن تا اولین نقطه
print(t[:s] )

ارسال جواب

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

×
بستن