0

我是 python 新手,我被分配为一家假设的酒店编写发票程序。尝试调用函数以获取其返回值时,我遇到了困难。我真的很难过,我真的可以使用帮助。实现代码将与程序的描述一起跟随,这样就可以知道究竟是什么错误。

Invoice

PCCC皇宫酒店

埃迪的帐单

入住天数:2

房费 $675.00

上网费用 $29.85

电视收费 $8.85

总费用 $703.70

地方税 $24.63

Total Due   $728.33

感谢您使用 PCCC 皇宫酒店。希望能再次见到你。

要求: • 按照课堂上的说明,在代码中以注释的形式包含相关信息。• 使用不同的函数来处理每个 o 房间类型 o 互联网接入使用 o 电视使用 • 互联网和电视使用可能会被拒绝,在这种情况下,费用将为 0.00 美元 • 所有费率都定义为内部的本地常数功能 • 每个功能都有一个菜单,显示可供选择的选项 • 每个功能返回该选项产生的费用 • 当地税率为 3.5%,定义为当地常数

问题是: Traceback(最近一次通话最后一次):文件“C:/Python33/hotel.py”,第 28 行,在 print("Room Charges:", roomcost()) NameError: name 'roomcost' is not defined

代码:

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: ")

房间费用()

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)
4

1 回答 1

1

roomcost 是一个函数,因此您需要使用 () 运算符以及其他函数调用来调用它:

print("Room Charges: ", roomcost())
print("Internet Charges: ", costofinternet())
print("Television Charges: ", costoftv())
于 2013-03-31T19:21:15.007 回答