At the conclusion of this programming assignment, participants should be able to:
Before starting this programming assignment, participants should be able to:
print()
statements, and collect input from the user with input()
Content used in this assignment is based upon information in the following sources:
Write a program (night_out.py) that simulates a night out on the town! The night out on the town is going to include that following activities (at a minimum):
Note: You can choose something other than a concert if you would like!
The program will keep track of the amount of money spent for each activity (and associated car parking for the activity), including tax and tip where appropriate!
Write a program that prompts the user to enter the following information:
The output of the program consists of the following:
Every money amount displayed to the user should have a dollar sign and be rounded to two decimal places.
ceil()
function from the math
module to do this!
* See round_up_to_nearest_dollar()
below.# example use of ceil
import math
print(math.ceil(5.2))
6
For this program, define the following functions:
display_instructions()
: Accepts no arguments. Prints instructions describing the use of the program to the user.get_tax_percent()
: Accepts no arguments. Prompts the user for the state sales tax as a percent. Returns the sales tax percent.get_tip_percent()
: Accepts no arguments. Prompts the user for what percentage of the bill (meal price + tax) they would like to tip. Returns the tip percent.get_price(activity_label)
: Accepts 1 argument via the parameter activity_label
, a string representing the price (before tax) to prompt the user for. Prompts the user to enter the price for activity_label
. Returns a string representing the city.get_price("dinner")
prompts the user with the string: "How much does dinner cost before tax?"calculate_tax(price, tax_percent)
: Accepts 2 arguments via the parameters price
, a float representing the cost of the activity and tax_percent
, a float representing the sales tax percent. Computes the tax for price
and returns the result as a floating point number.calculate_tip(price, tip_percent)
: Accepts 2 arguments via the parameters price
, a float representing the cost of the activity and tip_percent
, a float representing the percentage the user would like to tip. Computes the tip for price
and returns the result as a floating point number.round_up_to_nearest_dollar(price)
: Accepts 1 argument via the parameter price
, a float representing the cost of the activity. Rounds price
to the nearest dollar and returns the result as a floating point number.park_car()
: Accepts no arguments. Prompts the user for the cost to park their car and returns the result as a floating point number. Calls the following functions:get_price()
go_to_dinner(tax_percent)
: Accepts 1 argument via the parameter tax_percent
, a float representing the sales tax percent. Computes the total cost of dinner (meal + tax + tip, rounded to the nearest dollar) and returns the result as a floating point number. Calls the following functions:get_price()
get_tip_percent()
calculate_tax()
calculate_tip()
round_up_to_nearest_dollar()
go_to_concert(tax_percent)
: Accepts 1 argument via the parameter tax_percent
, a float representing the sales tax percent. Computes the total cost of the concert (concert tickets + tax) and returns the result as a floating point number. Calls the following functions:get_price()
calculate_tax()
display_money_spent(dinner_spent, concert_spent, parking_spent)
: Accepts 3 arguments via the parameters dinner_spent
, concert_spent
, and parking_spent
, which represent how much money the user spent on dinner, the concert, and parking, respectively. Displays the results.main()
function that drives the program. Calls the following functions:display_instructions()
get_tax_percent()
park_car()
go_to_dinner()
go_to_concert()
display_money_spent()
Feel free to define more functions as you see fit!
Here is an example run of the program:
Welcome to the night out simulator! This program will prompt you for the sales tax (as a percent) in your state.
Then it will walk you through your night out on the town, starting with dinner and ending with a concert!
The total amount of money spent for the evening will be kept track of, so you know how much your credit card bill will be!
What is the sales tax in your state (as a percentage)? 7.8
How much does parking cost? 1.25
How much does dinner cost before tax? 49.99
What percentage do you want to leave as a tip? 20
How much does parking cost? 5.00
How much does concert cost before tax? 75.50
After tax and tip, you spent $65.00 on dinner.
After tax, you spent $81.39 on the concert.
In total, you spent $6.25 on parking.
That means, you spent $152.64 this evening. Sounds like a lot of fun!
matplotlib
is a Python library that produces beautiful publication-quality visualizations. To use matplotlib
, we simply need to import it: import matplotlib
. I've written a function, plot_money_spent()
that accepts 6 arguments, 3 strings representing the activity labels for the night out and 3 floating point numbers representing the total spent for each activity:
import matplotlib.pyplot as plt
def plot_money_spent(label1, price1, label2, price2, label3, price3):
'''
111 STUDENTS: THIS IS THE FUNCTION YOU WILL CALL FOR THE **BONUS** TASK
Accepts 3 pairs of strings (activity labels) and 3 floats (money spent)
Ordering of the parameters is 3 pairs of activity label string, money spent value
Uses matplotlib functions to plot a bar graph of the activity prices.
Save the plot by clicking on the save button on the toolbar of the plot window.
Press the X to close the window when you are done.
This function does not return anything.
'''
x = [0, 1, 2]
x_labels = [label1, label2, label3]
y = [price1, price2, price3]
plt.bar(x, y)
plt.xticks(x, x_labels, ha='left')
plt.xlabel("Activity")
plt.ylabel("Price in Dollars")
plt.tight_layout()
# show the window
plt.show()
Copy and paste the above code into your night_out.py file. Do not modify the function plot_money_spent()
. Call plot_money_spent()
passing in the activity label strings and money spent for each activity. The function will show a window that looks like the following:
Save the plot as a .png image file by clicking on the save icon in the toolbar (highlighted in the screen shot above). Turn in your saved money spent plot image file in with your night_out.py file in your zip file.
<your last name>_pa2.zip
by the due date and time.Note: By submitting your code to be graded, you are stating that your submission does not violate the CptS 111 Academic Integrity Policy outlined in the Syllabus.
This assignment is worth 75 points + 5 points bonus. Your assignment will be evaluated based on a successful compilation and adherence to the program requirements. We will grade according to the following criteria:
display_instructions()
get_tax_percent()
get_tip_percent()
get_price()
calculate_tax()
calculate_tip()
round_to_nearest_dollar()
park_car()
go_to_dinner()
go_to_concert()
display_money_spent()
main()
function that drives the program.