The due date for this homework is Thursday, September 19th, 11:59pm EDT
This assignment is designed to give you practice with the following new topics:
.py
files to work in. Don’t change the filenames of those files.Your task is to complete following steps:
hw2_bill.py
, hw2_house.py
, and
hw2_stock.py
in the unzipped folder. You are expected to
write your programs in these files.hw2_stock.py
. This file is used in Part 1.hw2_house.py
. This file is used in Part 2.hw2_bill.py
. This file is used in Part 3.Notice that each starter .py
file has a header with some
information for you to fill in. Please do so. Your feedback helps the
instructors better understand your experiences doing the homeworks and
where we can provide better assistance.
When we are assessing your code, higher levels of achievement are demonstrated, in part, by
Your first task is to write a program (in hw2_stock.py
)
that computes the cost of buying stocks. The program asks the user for
their investment budget, a stock symbol, the current share price, and
the number of shares desired. The program informs the user of the
maximum number of shares they could buy and how much money would remain
if they bought the maximum or chosen number of shares.
A few important details: - When asking the user for a monetary
amount, the dollar sign ($
) should be included in the
prompt so the user only needs to enter the number. - The stock symbol
should be included in the prompts for the share price and number of
shares to buy. - All monetary values should be displayed with at most
two decimal places.
Example output 1
$$$$$ $TOCK INVE$TOR $$$$$
How much would you like to invest? $987.65
What is the stock symbol? AAPL
What is the share price for AAPL? $221.83
You can buy up to 4 shares and still have $100.33 left to invest
How many shares of AAPL would you like to buy? 3
Buying 3 shares costs $665.49
You will have $322.16 left to invest
Example output 2
$$$$$ $TOCK INVE$TOR $$$$$
How much would you like to invest? $123.45
What is the stock symbol? HPE
What is the share price for HPE? $16.41
You can buy up to 7 shares and still have $8.58 left to invest
How many shares of HPE would you like to buy? 7
Buying 7 shares costs $114.87
You will have $8.58 left to invest
Example output 3
$$$$$ $TOCK INVE$TOR $$$$$
How much would you like to invest? $100.01
What is the stock symbol? TEST
What is the share price for TEST? $20
You can buy up to 5 shares and still have $0.01 left to invest
How many shares of TEST would you like to buy? 1
Buying 1 shares costs $20.0
You will have $80.01 left to invest
Your task is to design and implement (in hw2_house.py
) a
program that creates a drawing of a house as text art.
Write code to draw a basic house:
[________|__|__]
[ ____ ____ ]
[ |__| |__| ]
[ |__| |__| ]
[ ]
[ ____ ____ ]
[ |__| |__| ]
[ |__| |__| ]
[ ]
[ ____ ____ ]
[ |__| |__| ]
[ |__| |__| ]
[________|__|__]
The drawing is made using only five distinct characters: spaces
(), underscores (
_
), vertical bars
(|
), left square brackets ([
), and right
square brackets (]
).
You must use separate functions for distinct features and to increase reusability while reducing repetition in your code. Note that there are distinct segments to the figure as well as repeated elements which lend themselves naturally to implementing as separate functions.
Modify your code to allow the user to customize the house. In particular, the user must be able to input: * The character to use on the base and roof of the house * A sequence of four characters to use above each window and door
Example output 1
Enter a character to use for the base/roof: .
Enter a sequence of characters to use above the windows and door: vVVv
[........|..|..]
[ vVVv vVVv ]
[ |__| |__| ]
[ |__| |__| ]
[ ]
[ vVVv vVVv ]
[ |__| |__| ]
[ |__| |__| ]
[ ]
[ vVVv vVVv ]
[ |__| |__| ]
[ |__| |__| ]
[........|..|..]
Example output 2
Enter a character to use for the base/roof: #
Enter a sequence of characters to use above the windows and door: +==+
[########|##|##]
[ +==+ +==+ ]
[ |__| |__| ]
[ |__| |__| ]
[ ]
[ +==+ +==+ ]
[ |__| |__| ]
[ |__| |__| ]
[ ]
[ +==+ +==+ ]
[ |__| |__| ]
[ |__| |__| ]
[########|##|##]
When you go out to dinner with friends, one person pays the entire bill and everyone else sends that person money (e.g., using Venmo) for their share of the bill. However, computing how much each person owes requires accounting for the cost of individual dishes, tax, and tip. You and your friends wish you had a program that could perform the computations for you.
We have provided a partial implementation of this program (in
hw2_bill.py
).
Add a docstring to each of the existing functions (in
hw_bill.py
), expect for main
.
Your docstring should be a short sentence that concisely summarizes what the function does.
main
Write the main
function.
Your main function must use the functions that are
already provided, and must not call any other functions
(e.g., print
, input
, float
). You
must not change the provided functions or write
additional functions. You may use variables and
operators (e.g., +
, -
, *
,
/
) in main.
Example output 1
This program assumes gratuity is not included in the bill
What percentage gratuity should be added? 15
How much is the total bill before tax? 73.56
How much is the total bill after tax? 79.45
Tax rate: 8.0%
How much is your dish? 14.99
You owe $18.44
Example output 2
This program assumes gratuity is not included in the bill
What percentage gratuity should be added? 18
How much is the total bill before tax? 53.46
How much is the total bill after tax? 56.93
Tax rate: 6.5%
How much is your dish? 10
You owe $12.45
Submit three Python files to the platform indicated in your class section:
hw2_stock.py
hw2_house.py
hw2_bill.py
Remember to complete the questions at the top of each file before submitting.