A simple Python command-line tool built for CodeAlpha – Python Programming Internship (Task 2).
Author: Adarsh Singh
Build a stock tracker that calculates total investment based on manually defined (hardcoded) stock prices.
- The user enters stock symbols and quantities.
- Stock prices are pulled from a hardcoded dictionary, e.g.:
{"AAPL": 180, "TSLA": 250, "GOOGL": 140, "AMZN": 175, "MSFT": 410} - The program calculates the total value of each holding and the overall total investment.
- The user can optionally save the summary to a
.txtor.csvfile.
- Dictionaries
- Input/Output (user input, console output)
- Basic arithmetic
- File handling (optional
.txt/.csvexport)
- Make sure you have Python 3 installed.
- Download
stock_portfolio_tracker.pyfrom this repo. - Open a terminal in that folder and run:
python stock_portfolio_tracker.py - Follow the on-screen prompts to enter stock symbols and quantities. Type
donewhen finished.
Stock symbol (e.g. AAPL): AAPL
Quantity of AAPL: 10
Stock symbol (e.g. AAPL): TSLA
Quantity of TSLA: 5
Stock symbol (e.g. AAPL): done
----- Portfolio Summary -----
AAPL: 10 shares x $180 = $1800
TSLA: 5 shares x $250 = $1250
------------------------------
TOTAL INVESTMENT: $3050
------------------------------
Save results to a file? (y/n): y
Save as 'txt' or 'csv'? csv
Saved to portfolio_summary.csv
stock_portfolio_tracker.py– main program
Part of the CodeAlpha Python Programming internship – Module 1, Task 2. Created by Adarsh Singh