From 65db71308d6adb3feabb17dd63cfdad7f6b40308 Mon Sep 17 00:00:00 2001
From: Priya Verma <146189957+Preaah05@users.noreply.github.com>
Date: Mon, 24 Mar 2025 19:49:17 +0530
Subject: [PATCH] Update exercise_2_stocks.py

---
 .../13_read_write_files/exercise_2_stocks.py  | 27 ++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/Basics/Exercise/13_read_write_files/exercise_2_stocks.py b/Basics/Exercise/13_read_write_files/exercise_2_stocks.py
index f71442ba..278e9406 100644
--- a/Basics/Exercise/13_read_write_files/exercise_2_stocks.py
+++ b/Basics/Exercise/13_read_write_files/exercise_2_stocks.py
@@ -1,12 +1,15 @@
-with open("stocks.csv", "r") as f, open("output.csv", "w") as out:
-    out.write("Company Name,PE Ratio, PB Ratio\n")
-    next(f)  # This will skip first line in the file which is a header
-    for line in f:
-        tokens = line.split(",")
-        stock = tokens[0]
-        price = float(tokens[1])
-        eps = float(tokens[2])
-        book = float(tokens[3])
-        pe = round(price / eps, 2)
-        pb = round(price / book, 2)
-        out.write(f"{stock},{pe},{pb}\n")
+from collections import Counter
+
+with open("poem.txt", "r") as file:
+    text = file.read().lower()
+
+words = text.split()
+
+word_count = Counter(words)
+
+max_count = max(word_count.values())
+
+most_frequent_words = [word for word, count in word_count.items() if count == max_count]
+
+print(f"Most frequent words: {most_frequent_words}")
+print(f"Occurrences: {max_count}")