简体   繁体   中英

functions and returns

I'm new to python and I've been assigned in writing an invoice program for a hypothetical hotel. I'm running into difficulty when trying to call on functions for their return value. I could really use the help as I'm really stumped. The implementation code is to follow along with the description of the program so a handle can be put on what exactly is the mistake.

Invoice

PCCC Palace Hotel

Eddie's Billing Statement

Number of days in hotel: 2

Room Charges $675.00

Internet Charges $29.85

Television Charges $8.85

Total Charges $703.70

Local Taxes $24.63

Total Due   $728.33

Thank you for using PCCC Palace Hotel. Hope to see you again.

Requirements: • Include relevant information in the form of comments in your code as explained in the class. • Use a different function to handle each of o the room type o The Internet Access usage o The TV usage • The Internet and TV usage may be denied, in that case the charges would be $0.00 • All the rates are defined as local constants inside the functions • Each function has a menu that displays the options to select from • Each function returns the charges incurred for that option • The local tax rate is 3.5% and is to be defined as a local constant

The problem is: Traceback (most recent call last): File "C:/Python33/hotel.py", line 28, in print("Room Charges: ", roomcost()) NameError: name 'roomcost' is not defined

Code:

def main():
input = int , 2
costofinternet = costofinternet
costoftv = costoftv


customername = input("The Customer Name Please: ")
visitdays = input("Enter the Number of Days in the Hotel: ")

room = input("Rooms Used \n1 - Single Room - One Bed \n2 - Family Room - Doulble Bed \n3 -      Suite \n Enter Choice 1, 2, or 3: ")

roomcost()

internet = input("Would You like Internet: ")
if internet == 'Y':
internettype = input("Internet Access Usage \n1 - Wireless \n2 - Wired \nEnter Choices 0, 1, or 2: ")

television = input("Would You like to use the TV: ")
if television == 'Y':
tvtype = input("TV Usage \n1 - Cable \n2 - Basic Channels \nEnter Choice 0, 1, or 2: ")

print("\t\t\t\t\t\t Invoice")
print("\t\tPCCC Palace Hotel")
print(customername, "'s Billing Statement")
print("Number of Days in Hotel: ", visitdays)
print("Room Charges: ", roomcost)
print("Internet Charges: ", costofinternet)
print("Television Charges: ", costoftv)
totalcharge = print("Total Charges: ", roomcost + costofinternet + costoftv)
localtaxes = print("Local Taxes: ", ((roomcost + costofinternet + costoftv) * .035))
print("\t\tTotal Due\t\t\t", totalcharge + localtaxes)
print("\t\tThank You For Using PCCC Palace Hotel. Hope To See You Again.")



def roomcost():
cost = []
if room == '1':
    cost == 225
if room == '2':
    cost == 325
if room == '3':
    cost == 550
return(cost)

def internet():
costofinternet = []
if internettype == '0':
    costofinternet == 0
if internettype == '1':
    costofinternet == 9.95
if internettype == '2':
    costofinternet == 5.95
return(costofinternet)

def tv():
costoftv = []
if tvtype == '0':
    costoftv == 0
if tvtype == '1':
    costoftv == 9.95
if tvtype == '2':
    costoftv == 2.95
return(costoftv)

roomcost is a function, so you'll need to call it using the () operator, along with your other function calls:

print("Room Charges: ", roomcost())
print("Internet Charges: ", costofinternet())
print("Television Charges: ", costoftv())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM