Skip to content

Commit 890e8fa

Browse files
author
Karandeep Grover
committed
changed paths
1 parent 8e59965 commit 890e8fa

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
with open("stocks.csv", "r") as f, open("output.csv", "w") as out:
2+
out.write("Company Name,PE Ratio, PB Ratio\n")
3+
next(f) # This will skip first line in the file which is a header
4+
for line in f:
5+
tokens = line.split(",")
6+
stock = tokens[0]
7+
price = float(tokens[1])
8+
eps = float(tokens[2])
9+
book = float(tokens[3])
10+
pe = round(price / eps, 2)
11+
pb = round(price / book, 2)
12+
out.write(f"{stock},{pe},{pb}\n")

Basics/Hindi/12_read_write_file/read_write_file_exercise.md renamed to Basics/Exercise/13_read_write_files/read_write_file_exercise.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## Exercise: Python Read Write File
2-
1. [poem.txt](https://github.com/codebasics/py/blob/master/Basics/Hindi/12_read_write_file/Exercise/poem.txt) contains famous poem "Road not taken" by poet Robert Frost. You have to read this file in your python program and find out words with maximum occurance.
2+
1. [poem.txt](https://github.com/codebasics/py/blob/master/Basics/Exercise/13_read_write_files/poem.txt) contains famous poem "Road not taken" by poet Robert Frost. You have to read this file in your python program and find out words with maximum occurance.
33

44

5-
[Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/12_read_write_file/Exercise/exercise_1_poem.py)
5+
[Solution](https://github.com/codebasics/py/blob/master/Basics/Exercise/13_read_write_files/exercise_2_stocks.py)
66

7-
2. [stocks.csv](https://github.com/codebasics/py/blob/master/Basics/Hindi/12_read_write_file/Exercise/stocks.csv) contains stock price, earnings per share and book value. You are writing a stock market application that will process this file and create a new file
7+
2. [stocks.csv](https://github.com/codebasics/py/blob/master/Basics/Exercise/13_read_write_files/stocks.csv) contains stock price, earnings per share and book value. You are writing a stock market application that will process this file and create a new file
88
with financial metrics such as pe ratio and price to book ratio. These are calculated as,
99
```
1010
pe ratio = price / earnings per share
@@ -26,4 +26,4 @@ Output.csv should look like this,
2626
|Reliance|22.23|2.25|
2727
|Tata Steel|4.39|0.68|
2828

29-
[Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/12_read_write_file/Exercise/exercise_2_stocks.py)
29+
[Solution](https://github.com/codebasics/py/blob/master/Basics/Exercise/13_read_write_files/exercise_2_stocks.py)

Basics/Hindi/12_read_write_file/Exercise/exercise_2_stocks.py

-12
This file was deleted.

0 commit comments

Comments
 (0)