Robotics & Artificial Intelligence
Write a Python program to do the following tasks.
- Input a sentence and store it to a string variable.
- Print the length of the string, its first character, and its last character.
- Use a loop to traverse through the string and print the total number of digits present.
Python String Manipulation
1 Like
Answer
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)Output
Enter a sentence: Hello123 World45
Length of the string: 16
First character: H
Last character: 5
Total number of digits: 5
Answered By
1 Like
Related Questions
Name the type of sensor used for each of the following purposes:
(a) Detecting obstacles
(b) Measuring light intensity
(c) Measuring temperatureExplain software theft. Mention any two consequences of software theft.
Briefly describe the different types of joints in robotics.
What is data theft? Give any two causes of data theft.