酷代码 AI
菜单
服务商

编写程序,输入一段英文文本(不包含任何标点符号),实现文本中每个单词(不区分大小写)出现的次数,并将结果输出。输出格式示例:i2 you1 he2

以下是使用 Python 实现的代码: ```python def count_words(text): text = text.lower() # 将所有字母转换为小写,以便不区分大小写 words = text.split() # 按空格分割单词 word_count = {} for word in words: if word in word_count: word_count[word] += 1 else: word_count[word] = 1 result = "" for word, count in word_count.items(): result += word + str(count) return result text = input("请输入英文文本(不包含标点符号):") print(count_words(text)) ``` [2024-10-17 11:38:00 | AI写代码神器 | 151点数解答]

相关提问
实用工具查看更多
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]
数独游戏 [娱乐类]
经典推箱子 [娱乐类]
AI摸鱼五子棋 [娱乐类]