Last active
December 5, 2017 02:30
-
-
Save stockwellb/5a73c1fe2c79af50646b1a4970b42d3e to your computer and use it in GitHub Desktop.
Katya's final
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Katya Ruiz | |
#Final Project for COP 1000 | |
#12/1/2017 | |
#This is a program for calculating room sales for a stay | |
#at a Bed and Breakfast called Casa San Agustin in St. Augustine, FL. | |
#Global constants: | |
DISCOUNT_RATE = 0.10 | |
SALES_TAX = 0.08 | |
#Main function | |
def main(): | |
#Declare variables: | |
roomRate = 0.0 | |
subtotal = 0.0 | |
discount = 0.0 | |
total = 0.0 | |
roomChoice = 0 | |
numNights = 0 | |
#Display room options and rates | |
print ('Please choose a room.\n') | |
print ('Room \t\t Description \t\t Rate') | |
print ('------------------------------------------------') | |
print ('Room Artes \t std queen room \t $199.99') | |
print ('Room Lujo \t luxe queen room \t $249.99') | |
print ('Room Luna \t honeymoon suite \t $349.99\n') | |
#Let user enter room choice | |
print ('Enter 1 for Room Artes') | |
print ('Enter 2 for Room Lujo') | |
print ('Enter 3 for Room Luna\n') | |
roomChoice = int(input('Enter your selection here: ')) | |
if roomChoice == 1: | |
roomRate = 199.99 | |
elif roomChoice == 2: | |
roomRate = 249.99 | |
elif roomChoice == 3: | |
roomRate = 349.99 | |
print ('''You have chosen the honeymoon suite. This room | |
includes a complimentary bottle of wine and a box of chocolates | |
in your room upon check-in.\n''') | |
else: | |
print ('You have entered an invalid option.') | |
numNights = int(input('Enter the number of nights: ')) | |
#Get input from user on discount eligibility | |
yes = 'y' | |
yes = str(input('''\nEnter "y" if you are an active duty member | |
of the military or a senior. Otherwise enter "n": ''')) | |
#Enter the decision structure to determine discount eligibility | |
if yes == 'y': | |
#Call the calcDiscount function | |
discount = calcDiscount(roomRate) | |
#Call the calcSubtotal function | |
subtotal = calcSubtotal (roomRate, numNights, discount) | |
else: | |
#Call the calcSubtotal function | |
subtotal = calcSubtotal(roomRate, numNights, discount) | |
#Call the calcTotal function | |
total = calcTotal(subtotal) | |
print (total) | |
#Display the totals and the thank you message | |
print ('\nThe subtotal, including any discounts, is $',format(subtotal,'.2f')) | |
print ('The total, including all taxes and fees, is $',format(total,'.2f')) | |
print ('''\nThank you for choosing to stay at Casa San Agustin. | |
We hope you enjoy your visit.''') | |
#Define the calcDicount function | |
def calcDiscount(roomRate): | |
return roomRate * DISCOUNT_RATE | |
#Define the calcSubtotal function | |
def calcSubtotal(roomRate, numNights, discount): | |
return (roomRate * numNights) - discount | |
#Define the calcTotal function | |
def calcTotal(subtotal): | |
return subtotal + (subtotal*SALES_TAX) | |
#Call main | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@katya8020 Think of a function as a black box. You put things in it and get things out of it. What goes on inside isn't your concern. This is how your
main()
uses functions likecalcSubtotal()
. The functions don't change anything that isn't inside them. This makes them reusable. They way you had it before, the functions where trying to change global variables. The rule that Python follows states that when a function creates a variable with the same name as one in the global scope, it will shadow it. In other words the variable is only in affect inside the function. Python is trying to keep the function as a black box.