为了账号安全,请及时绑定邮箱和手机立即绑定

如何获取最大价值

如何获取最大价值

qq_花开花谢_0 2021-06-29 13:00:53
Enter 10 for first inputenter 500 for second inputenter 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=10fixed_cost=2500print("\n")for numberpass in range(MP,max_passengers+10,increment):    discount=.5    ticketcost =  TP - (((numberpass - MP) /10) * discount)    gross=numberpass*ticketcost    profit=gross-fixed_costprint(numberpass,"\t",ticketcost,"\t",gross,"\t",fixed_cost,     "\t",profit)
查看完整描述

1 回答

?
MM们

TA贡献1886条经验 获得超2个赞

将每个利润保存在一个列表中,然后取该列表的最大值:


# rest of you code above...

profits = [] # create the list to store the every profit

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)


    profits.append(profit) # store each profit


max_profit = max(profits)

print("Maximum profit: {}".format(max_profit))


查看完整回答
反对 回复 2021-07-13
  • 1 回答
  • 0 关注
  • 177 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号