求一段python的编程
发布网友
发布时间:2024-02-27 06:42
我来回答
共3个回答
热心网友
时间:2024-03-21 02:58
sentence = raw_input("Enter a sentence : ")
while sentence.find(" ") != -1:
i = sentence.find(" ")
print sentence[:i] + " (length: " + str(len(sentence[:i])) + ")"
sentence = sentence[i+1:]
print sentence + " (length: " + str(len(sentence)) + ")"
热心网友
时间:2024-03-21 02:58
text = "I am a student"
for i in ["%s (length:%d)"%(i,len(i)) for i in text.split(" ")]:
print i
热心网友
时间:2024-03-21 03:03
import re
s = raw_input("input a string:\n")
p = re.findall(r'\w+', s)
for i in p:
print "%s (length: %i)"%(i,len(i))