teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2021/09/18 02:50

投稿

bsdfan
bsdfan

スコア4921

answer CHANGED
@@ -8,4 +8,22 @@
8
8
  print(i)
9
9
  else:
10
10
  print("なんとも言えん")
11
+ ```
12
+
13
+ **追記**
14
+
15
+ scoreが0以上の個数を数えたいなら、個数を数える変数を用意して、ifの中で増やしていけばいいです。
16
+
17
+ ```python
18
+ n = 0
19
+ for i in text_normalize():
20
+ sia = SentimentIntensityAnalyzer()
21
+ score = sia.polarity_scores(i)["neg"] - sia.polarity_scores(i)["pos"]
22
+ if score >= 0.0:
23
+ print(i)
24
+ n += 1
25
+ else:
26
+ print("なんとも言えん")
27
+
28
+ print('score >= 0 の個数:', n)
11
29
  ```