Week 3: Control Flow: Conditional Statements and Loops
Learn how to make decisions and repeat tasks in Python, essential for financial analysis and automated trading strategies.
Learning Objectives:
- ✓ Understand the concept of control flow in programming
- ✓ Learn how to use conditional statements (if, else, elif) in Python
- ✓ Learn how to use loops (for, while) in Python
- ✓ Use Flowcharts to guide your coding projects
Exercises:
- Write a program that:
- Takes a stock price as input
- If price > 100, print "High-priced stock"
- If 50 ≤ price ≤ 100, print "Medium-priced stock"
- If price < 50, print "Low-priced stock"
- Create a program that calculates compound interest over multiple years using a loop
- Write a program that analyzes a list of stock prices and:
- Finds the highest and lowest prices
- Calculates the average price
- Counts how many days the price was above average
- Create a simple trading simulator that:
- Loops through daily prices
- Uses if statements to make buy/sell decisions
- Tracks portfolio value
- Write a program that calculates the total return of an investment with monthly contributions over a period of years
- Create a loan payment calculator that shows the remaining balance after each payment using a loop
💡 ChatGPT Learning Tips
Use these prompts to enhance your learning:
- "Show me how to use if-else statements to create a basic stock trading decision system"
- "Explain how to use a for loop to calculate compound interest over multiple years"
- "Help me create a flowchart for a simple trading strategy using Python"
- "What are common patterns in financial calculations that use loops?"