嗨,所以我是一個Python初學者,我有點卡住了我有類的問題,並希望對此有一些指導。 課堂問題是:體育場座位:運動場有三個座位類別。對於棒球比賽而言,A級座位每人收費15美元,B級座位每人收費12美元,C級座位每人收費9美元。創建一個python程序,允許用戶輸入每個班級出售的門票數量。該計劃應該能夠顯示每個門票銷售類別產生的收入數量以及產生的總收入。 爲門票數量添加輸入驗證,以便僅允許輸入數字。你的程序不能讓剩下的代碼以無效的輸入運行。卡在一個體育場python代碼
現在我得到了大部分的工作,但由於某種原因,我的收入2和3沒有乘以價格的門票數量,而只是寫了多少次門票的價格。它似乎是隻有實現了B級和C
這裏是我的代碼
sales1=input("Enter number of tickets sold for Class A seats:")
#Validating sale
while not sales1.isnumeric():
print("INVALID INPUT:Please enter a number:")
#Convert sales to a number
sales1 =int(sales1)
sales2=input("Enter number of tickets sold for Class B seats:")
#Validating sale
while not sales2.isnumeric():
print("INVALID INPUT:Please enter a number:")
#Convert sales to a number
sales =int(sales2)
sales3=input("Enter number of tickets sold for Class C seats:")
#Validating sale
while not sales3.isnumeric():
print("INVALID INPUT:Please enter a number:")
#Convert sales to a number
Sales2 =int(sales3)
#Income
income1 = int(sales1 * 15)
print("Sales for Class A:$" , end="")
print(income1)
income2 = int(sales2 * 12)
print("Sales for Class B:$" , end="")
print(income2)
income3 = int(sales3 * 9)
print("Sales for Class C:$" , end="")
print(income3)
#Total
Total = int(income1 + income2 + income3)
print("Total revenue from ticket sales:$")
print (total)
我的結果看起來就像這樣
輸入A類席位賣出的門票數量:1 輸入門票銷售數量B類座位s:1 輸入C級座位的門票數量:1 A級的銷售額:15美元。 銷售B級:$ 111111111111 銷售C類:$ 111111111
你需要調用'int(sales1)* 15' ...乘以字符串在python中工作,但它重複的字符串,這不是你在之後。 –
脫離主題......但o親愛的上帝,如果他們沒有輸入有效的整數會發生什麼?!...他們沒有得到重新輸入的選項....它只是使垃圾郵件無效! (我可能是錯的......在一段時間內沒有處理python ......) – TheOneWhoPrograms