Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem #3: A Stock Market Investment (10 points) You have purchased 20 shares of a single stock for $200 a share, for a total cost
Problem \#3: A Stock Market Investment (10 points) You have purchased 20 shares of a single stock for $200 a share, for a total cost of $4000. Simulate the price fluctuations of this stock. Each day, the price can go up or down by one, two or three dollars or remain the same. To get a random change, you can import the random module and then run the following statement in your program, which will randomly choose one of the integers between -3 and 3. change = random. randint (3,3) Use a while loop to simulate changing the stock price each day over however many days it takes until the price either falls below $150 or above $250. If you lost money (the price fell below $150 ), give the number of days that have elapsed, the phrase "You cut your losses" and the amount of your loss. If you made money (the price went above $250 ), give the number of days that have elapsed, the phrase "You cashed out" and the amount of your gain. No user input is required. Following are two sample runs of the program. You may get different results due to randomness. 751 days have elapsed. The final price was $252. You cashed out. You made $1040. 280 days have elapsed. The final price was $148. You cut your losses. Problem \#5: Statistics on the Number of Days Elapsed (Optional, Extra Credit, 10 Points) Remove all the output from problem \#3. Then wrap it in another loop that runs it 1000 times. Considering the number of days elapsed during each of the 1000 runs, what was the maximum number of days of all the runs? The minimum number? The average number? Grading: Five points correct logic, three points correct output, two points comments Note: extra credit only counts toward your assignments grade, and your assignments grade cannot exceed 100%. So doing this extra credit will only help you if you lose points somewhere else on this assignment or another assignment
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started