From 8989b19e7eef9e5abef6e6b70d76baf8c9ba3fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=89=BF=E6=B4=8B?= <10655261+foxesLee@user.noreply.gitee.com> Date: Fri, 25 Mar 2022 10:29:12 +0000 Subject: [PATCH] =?UTF-8?q?add=20homework=5F01=5Fpython/1.=20=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1. \345\255\227\347\254\246\344\270\262" | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 "homework_01_python/1. \345\255\227\347\254\246\344\270\262" diff --git "a/homework_01_python/1. \345\255\227\347\254\246\344\270\262" "b/homework_01_python/1. \345\255\227\347\254\246\344\270\262" new file mode 100644 index 0000000..d3e64f4 --- /dev/null +++ "b/homework_01_python/1. \345\255\227\347\254\246\344\270\262" @@ -0,0 +1,10 @@ +# 1. 字符串:给定一个文章,找出每个单词的出现次数。 + +str1 = "One is always on a strange road, watching strange scenery and listening to strange music. Then one day, you will find that the things you try hard to forget are already gone. " + +str1 = str1.replace(',', '').replace('.', '') +str1 = str1.split() +word = set(str1) +for i in word: + count = str1.count(i) + print(i, ':', count, '次') \ No newline at end of file -- Gitee