Skip to content

Commit

Permalink
changed paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Karandeep Grover committed Feb 15, 2021
1 parent 8e59965 commit 890e8fa
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
12 changes: 12 additions & 0 deletions Basics/Exercise/13_read_write_files/exercise_2_stocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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")
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Exercise: Python Read Write File
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.
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.


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

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
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
with financial metrics such as pe ratio and price to book ratio. These are calculated as,
```
pe ratio = price / earnings per share
Expand All @@ -26,4 +26,4 @@ Output.csv should look like this,
|Reliance|22.23|2.25|
|Tata Steel|4.39|0.68|

[Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/12_read_write_file/Exercise/exercise_2_stocks.py)
[Solution](https://github.com/codebasics/py/blob/master/Basics/Exercise/13_read_write_files/exercise_2_stocks.py)
12 changes: 0 additions & 12 deletions Basics/Hindi/12_read_write_file/Exercise/exercise_2_stocks.py

This file was deleted.

0 comments on commit 890e8fa

Please sign in to comment.