Programming Examples

Write a Python program that:


Write a Python program that:

(a) Accepts a sentence from the user as input.

(b) Displays the first 5 characters and the last 5 characters of the sentence using slicing.

(c) Concatenates the sentence with another predefined string.

Solution

sentence = input("Enter a sentence: ")

# Display first 5 characters
first_five = sentence[:5]

# Display last 5 characters
last_five = sentence[-5:]

print("First 5 characters:", first_five)
print("Last 5 characters:", last_five)

# Concatenate with another predefined string
extra = " - Thank you!"
new_sentence = sentence + extra

print("Concatenated sentence:", new_sentence)
Output

Enter a sentence: Welcome to Python Programming

First 5 characters: Welco

Last 5 characters: mming

Concatenated sentence: Welcome to Python Programming - Thank you!

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad