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.
Solutionsentence = 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)
▶ RUN Output/ Explanation: Enter a sentence: Welcome to Python Programming
First 5 characters: Welco
Last 5 characters: mming
Concatenated sentence: Welcome to Python Programming - Thank you!