Как принять наибольшее значение

1
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)
Теги:

1 ответ

0
Лучший ответ

Сохраните каждую прибыль в списке, затем возьмите максимальное значение этого списка:

# 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))
  • 0
    Огромное спасибо :)
  • 0
    Рад помочь! Принятие ответа будет приветствоваться;)

Ещё вопросы

Сообщество Overcoder
Наверх
Меню