[英]functions and returns
我是python的新手,並且已經為一個假設的酒店編寫發票程序而受委派。 嘗試為函數的返回值調用函數時,我遇到了困難。 我真的很沮喪,可以使用幫助。 實現代碼將與程序說明一起使用,以便可以對錯誤的確切原因進行處理。
Invoice
PCCC皇宮酒店
埃迪的帳單
在酒店的天數:2
客房費用$ 675.00
互聯網收費$ 29.85
電視費$ 8.85
總費用$ 703.70
地方稅$ 24.63
Total Due $728.33
感謝您使用PCCC皇宮酒店。 希望能再次見到你。
要求:•按照課程中的說明,以注釋的形式包括相關信息。 •使用不同的功能來處理每種o類型的房間o互聯網使用情況o電視使用情況•Internet和電視使用情況可能會被拒絕,在這種情況下,費用為$ 0.00•所有費率均定義為內部的本地常量功能•每個功能都有一個菜單,顯示要選擇的選項•每個功能返回該選項產生的費用•本地稅率為3.5%,應定義為本地常量
問題是:追溯(最近一次呼叫最近):文件“ C:/Python33/hotel.py”,第28行,在打印中(“ Room Charges:”,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)
roomcost是一個函數,因此您需要使用()運算符以及其他函數調用來調用它:
print("Room Charges: ", roomcost())
print("Internet Charges: ", costofinternet())
print("Television Charges: ", costoftv())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.