write a program to input a sentence and print each word of the string along with its length in tabular form
plzz guys do not spam
Answers
Answered by
3
import re
from string import punctuation
def main(s):
print("Word", "Length")
for word in re.sub('['+punctuation+']', '', s).split():
word_len = len(word)
diff = abs(word_len - 5)
print(f"{word}{' ' * diff}{word_len}") if diff > 0 else print(word, len(word))
main((s := input("string: ")))
Similar questions
Social Sciences,
2 months ago
Biology,
2 months ago
Computer Science,
2 months ago
Math,
6 months ago
Science,
6 months ago
Science,
11 months ago
Physics,
11 months ago