Skip to content

Instantly share code, notes, and snippets.

@stockwellb
Last active December 5, 2017 02:30
Show Gist options
  • Save stockwellb/5a73c1fe2c79af50646b1a4970b42d3e to your computer and use it in GitHub Desktop.
Save stockwellb/5a73c1fe2c79af50646b1a4970b42d3e to your computer and use it in GitHub Desktop.
Katya's final
#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()
@katya8020
Copy link

Thank you! I'm working on trying to understand shadowed variables, and how lines 51, 53, 56, and 58 are calls to functions, since they seem to assign a value to a variable. I didn't know a call to a function could do that.

The only little issue I found when plugging in numbers was the calcDiscount function. I found the math to work better by changing it to the following:
def calcDiscount (roomRate, numNights):
return (roomRate * numNights) * DISCOUNT_RATE

@stockwellb
Copy link
Author

stockwellb commented Dec 5, 2017

@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 like calcSubtotal(). 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment