猿问

如何获取最大价值

Enter 10 for first input

enter 500 for second input

enter 20 for third input

我想知道是否有一种方法可以让我获得最大利润并显示它而无需用户阅读每一行?


MP=abs(int(input("Enter the minimum number of passengers:")))

print(MP)

max_passengers=int(input("Enter the maximum number of passengers:"))


while(max_passengers <= MP):

        print("\n")

        max_passengers=int(input("You must enter a number that is greater than the minimum ammount of passengers:"))


print(max_passengers)

TP=float(input("Enter the ticket price"))

print(TP)

increment=10

fixed_cost=2500

print("\n")


for numberpass in range(MP,max_passengers+10,increment):

    discount=.5

    ticketcost =  TP - (((numberpass - MP) /10) * discount)

    gross=numberpass*ticketcost

    profit=gross-fixed_cost


print(numberpass,"\t",ticketcost,"\t",gross,"\t",fixed_cost, 

    "\t",profit)


qq_花开花谢_0
浏览 178回答 1
1回答

MM们

将每个利润保存在一个列表中,然后取该列表的最大值:# rest of you code above...profits = [] # create the list to store the every profitfor numberpass in range(MP,max_passengers+10,increment):&nbsp; &nbsp; discount=.5&nbsp; &nbsp; ticketcost =&nbsp; TP - (((numberpass - MP) /10) * discount)&nbsp; &nbsp; gross=numberpass*ticketcost&nbsp; &nbsp; profit=gross-fixed_cost&nbsp; &nbsp; print(numberpass,"\t",ticketcost,"\t",gross,"\t",fixed_cost,"\t",profit)&nbsp; &nbsp; profits.append(profit) # store each profitmax_profit = max(profits)print("Maximum profit: {}".format(max_profit))
随时随地看视频慕课网APP

相关分类

Python
我要回答