Question: Chapter 7: a couple of functions for a small business Student: Justin Thrasher
""" Chapter 7: a couple of functions for a small business Student: Justin Thrasher <-- add your name here File: ch7_vinyl_business_functions_v6.py Course: CIS 156, CGCC Initial source: Copyright 2022 David Baker """
import datetime
# Part 1: fix this function to properly print a receipt """ Here is a complete receipt (using Gilbert as an example): Vintage Vinyl on Wheels Sat, Oct 15, 2022, 09:54:18 AM Today we're in Gilbert, Arizona Merchandise $9.00 Sales Tax $0.70 Total $9.70 Thank you for shopping with us! """ # Note the proper spacing of city and state, with a comma # Note the formatting in US dollars # Note the nice column format # Your output should duplicate this formatting exactly
def print_receipt(our_location, price_of_cart_items, sales_tax): """Prints the receipt of this customer's transaction Parameters: our_location (tuple): ('City', 'State') as strings price_of_cart_items (float): the pre-tax price for the cart item(s) sales_tax (float): sales tax Return: None """ print(" Vintage Vinyl on Wheels") print(today_timestamp()) display_current_location(our_location)
print(f'{"Merchandise":<12}{format_USD(price_of_cart_items):>11}') # Okay, I've written part of this function, you need to finish it. # Everything you need has been sent into this function and is available to you # The code above that prints the Merchandise line can be a model for the rest of your code # Add an output line for sales tax and another for the total. # Use an f-string in your print statement. # Note - your output won't have the nice currency formatting until # you complete the format_USD function # Your solution goes here
# end of your code print("Thank you for shopping with us!") # End of print_receipt function ########### # Part 2 - fix this function to work properly def format_USD(cash): """Accepts a float, returns a properly formatted string in US dollars and cents""" # As you find it, it doesn't do anything.. just returns the input # modify as needed, fixing my do-nothing return cash statement # Use an f-string to format cash so it looks like currency with a $ and 2 decimal places. # Your solution goes here cash_string = ""; #string to hold your f-string that formats cash - need to complete return cash # when you have cash_string completed, then update this line to return cash_string
########## end of format_USD() ##########
# Part 3 - fix this printout to get the correct spacing. def display_current_location(our_location): """Prints the current location Parameters: our_location (tuple): with two strings in the form ('City', 'State') Return: None """ city, state = our_location
# Fix the following print statement to properly space the city and state # See the example printout in Part 1 for the exact formatting specification # You can use any of the techniques we have learned
print("FIXME: Today we're in ", city, ', ', state)
########## end of display_current_location() ##########
### my functions - do not edit but take a look ### def get_sales_tax(our_location, price_of_cart_items): """Calculate sales tax STUB FUNCTION: Only a few states and cities are implemented right now, returns zero for others Parameters: our_location (tuple): ('City', 'State') as strings price_of_cart_items (float): the pre-tax price for the cart item(s) Returns: float: sales tax """
city, state = our_location #unpack the tuple so we can work with the two values if state == "Arizona": if city == "Phoenix": return price_of_cart_items * 0.086 if city == "Gilbert": return price_of_cart_items * 0.078 if city == 'Winslow': return price_of_cart_items * 0.0943 if city == "Sedona": return price_of_cart_items * 0.0985 if city == "Pinetop": return price_of_cart_items * 0.0943 return price_of_cart_items * 0.056 elif state == "California": return price_of_cart_items * 0.0725 elif state == "Colorado": if city == "Basalt": return price_of_cart_items * 0.082 return price_of_cart_items * 0.029 elif state == "Nevada": return price_of_cart_items * 0.0685 else: return 0.0 ########## end of get_sales_tax() ########## #### helper functions ####
def today_timestamp(): """Get today's date and time, return as a string""" currentDT = datetime.datetime.now() return currentDT.strftime("%a, %b %d, %Y, %I:%M:%S %p")
def splash_screen(): print("Chapter 7: Add a nice sales receipt for our small business, v6") print("We sell vintage vinyl and other music from our RV, traveling around small towns") def goodbye(): print(" ***End of program***")
def main(): splash_screen() print(' HOMEWORK TESTING MODE: we will try just two fake customers') print('Our first customer will be in Pinetop, AZ. The second in Basalt, CO') print(' Customer #1 in Pinetop, has 3 older records, marked just $3 each, so $9.00 to ring up') current_location = ('Pinetop', 'Arizona') price_of_cart_items = 9.00 print_receipt(current_location, price_of_cart_items, get_sales_tax(current_location, price_of_cart_items))
print(' Customer #2 in Basalt has just 2 records in their cart, marked $6.00 each, so $12.00 for the merchandise') current_location = ('Basalt', 'Colorado') price_of_cart_items = 12.00 print_receipt(current_location, price_of_cart_items, get_sales_tax(current_location, price_of_cart_items)) goodbye()
# call main if __name__ == '__main__': main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
