我是新來的python,我已經寫了一個假想酒店的發票程序。嘗試調用函數返回值時遇到困難。我真的可以使用幫助,因爲我真的很難過。實現代碼將跟隨程序的描述,以便處理可能發生的錯誤。函數和返回
Invoice
PCCC皇宮酒店
埃迪的帳單內容
在酒店的天數:2
房費$ 675.00
互聯網收費$ 29.85,增幅
電視收費$ 8.85
的總費用$ 703.70
地方稅$ 24.63
Total Due $728.33
感謝您使用PCCC皇宮酒店。希望能再次見到你。
要求: •在課堂上以代碼中的註釋形式提供相關信息。 •使用不同的函數來處理每個 Ø房型 ○上網使用 ○電視使用 •互聯網與電視的使用可能會被拒絕,在這種情況下,費用將介於$ 0.00 •所有費率被定義爲函數內的局部常量 •每個函數都有一個菜單,顯示可從 中選擇的選項•每個函數返回該選項產生的費用 •地方稅率爲3.5%,並被定義爲本地常量
問題是: 回溯(最近呼叫最後一次): 文件「C:/ Python33/hotel.py」 28行,在 打印( 「房費」,roomcost()) NameError:名字 'roomcost' 沒有定義
代碼:
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)
你正在濫用'=='和'='。 '=='檢查是否相等('5 == 5'返回'True'),'='是賦值運算符('x = 5'意思是'x'現在是5)。 –