Homework 4, Problem 2: TT
Securities, Incorporated
[30
points; individual or pair]
Submission: Submit your hw4pr2.py file to Canvas!
For this problem, you will
implement a (text-based) menu of options for analyzing a list of stock prices
(or any list of floating-point values). This provides an opportunity to use
loops in a variety of ways, as well as experience handling user input.
The top-level function to write
is called tts() --
it takes no inputs. Instead, it offers the user a menu with these choices:
(0) Input a new list
(1) Print the current list
(2) Find the average price
(3) Find the standard deviation
(4) Find the min and its day
(5) Find the max and its day
(6) Your TT investment plan
(9) Quit
Enter your choice:
Feel free to change the wording
or text, but please keep the functionality of these choices intact. If you'd
like to add additional menu options of your own design, please use different
values for them (see extra credit, below).
Once the menu is presented, the
program should wait for the user's input. (You may assume that the user will
type an integer as input.) The function should then
For any option except 9, the function
should reprompt the user with the menu after each choice.
Most of the calculations are
straightforward, but here are a couple of pointers on two of them:
Below is an example run that
illustrates one possible interface for your tts() function.
Helper functions
You should
write a helper function for each of the menu options.
Extra credit: creative menu options
(up to +10 pts)
If you'd like, you may add other menu options (under
different numeric labels) that process the list in some other way of your
design -- it can be serious or not. Either way, your options will be graded on
what they do and how smoothly they interact with the user.
Here is an example run -- you do not need to follow this format exactly (though
you may), but it's meant to show an example of each possibility:
>>> tts()
(0) Input a new list
(1) Print the current list
(2) Find the average price
(3) Find the standard deviation
(4) Find the min and its day
(5) Find the max and its day
(6) Your TT investment plan
(9) Quit
Enter your choice: 0
Enter a new list of prices: [20,10,30]
(0) Input a new list
(1) Print the current list
(2) Find the average price
(3) Find the standard deviation
(4) Find the min and its day
(5) Find the max and its day
(6) Your TT investment plan
(9) Quit
Enter your choice: 1
Day Price
--- -----
0 20.00
1 10.00
2 30.00
(0) Input a new list
(1) Print the current list
(2) Find the average price
(3) Find the standard deviation
(4) Find the min and its day
(5) Find the max and its day
(6) Your TT investment plan
(9) Quit
Enter your choice: 2
The average price is 20.0
(0) Input a new list
(1) Print the current list
(2) Find the average price
(3) Find the standard deviation
(4) Find the min and its day
(5) Find the max and its day
(6) Your TT investment plan
(9) Quit
Enter your choice: 3
The st. deviation is 8.16496580928
(0) Input a new list
(1) Print the current list
(2) Find the average price
(3) Find the standard deviation
(4) Find the min and its day
(5) Find the max and its day
(6) Your TT investment plan
(9) Quit
Enter your choice: 4
The min is 10 on day 1
(0) Input a new list
(1) Print the current list
(2) Find the average price
(3) Find the standard deviation
(4) Find the min and its day
(5) Find the max and its day
(6) Your TT investment plan
(9) Quit
Enter your choice: 5
The max is 30 on day 2
(0) Input a new list
(1) Print the current list
(2) Find the average price
(3) Find the standard deviation
(4) Find the min and its day
(5) Find the max and its day
(6) Your TT investment plan
(9) Quit
Enter your choice: 6
Your TTS investment strategy is to
Buy on day 1 at price 10
Sell on day 2 at price 30
For a total profit of 20
(0) Input a new list
(1) Print the current list
(2) Find the average price
(3) Find the standard deviation
(4) Find the min and its day
(5) Find the max and its day
(6) Your TT investment plan
(9) Quit
Enter your choice: 7
The choice 7 is not an option.
Try again
(0) Input a new list
(1) Print the current list
(2) Find the average price
(3) Find the standard deviation
(4) Find the min and its day
(5) Find the max and its day
(6) Your TT investment plan
(9) Quit
Enter your choice: 9
See you yesterday!
If
you have gotten to this point, you have completed problem2. You should submit your hw4pr2.py
file at Canvas .
Next