Write a Python program to do the following tasks.

ICSE Class 10 Robotics & AI PYQ · 2026 Paper · Section B

5(iii)Written · 2026 · Section B · 2026 Paper

Write a Python program to do the following tasks.

Show SolutionHide Solution↓
sentence = input("Enter a sentence: ")

l = len(sentence)
fc = sentence[0]
lc = sentence[-1]

print("Length of the string:", l)
print("First character:", fc)
print("Last character:", lc)

count = 0
for ch in sentence:
    if ch.isdigit():
        count += 1

print("Total number of digits:", count)
Enter a sentence: Hello123 World45
Length of the string: 16
First character: H
Last character: 5
Total number of digits: 5
← Previous questionNext question →

Browse the free Robotics & AI sample bank