Library contents

Python max

Choose the larger of the reserved count and the current seating target.

A simple example

max

  1. Start with 2 and 5
  2. Do this Choose the larger value
  3. Result 5
Comparing the two numbers places 5 above 2.
lesson.py
print(max(2.0, 5.0))
Output
5.0

Syntax

Python syntax
max(booked, capacity)
Run these examples in Python

Save one example at a time as lesson.py. Use Python 3.9 or later.

python3 lesson.py

Keep enough seats for a booking

A booking screen receives a requested party size and the current seat inventory. Use the available capacity to decide how many places can actually be assigned.

From the programbooked = 18.0
Result20.000
lesson.py
booked = 18.0
capacity = 20.0

print(f"{max(booked, capacity):.3f}")
Output
20.000

Eighteen bookings and a seating target of twenty require planning for twenty places.

Advertisements

Record the busiest hour at a help desk

A help desk is planning coverage for its busiest period. Compare the recorded hourly loads to identify the peak that the next shift needs to handle.

From the programbaseline = 15.0
Result23.000
lesson.py
baseline = 15.0
current = 23.0

print(f"{max(baseline, current):.3f}")
Output
23.000

The current count of 23 exceeds the previous record of 15.

Keep the busiest counter reading

A librarian has recorded a peak of 17 checkouts in an hour. The current hour reaches 21 and the dashboard refreshes its peak.

GivenEarlier peak 17 · now 21
Worked result21

Taking the greater count updates the peak only when demand rises.

What to watch for

This selects one value. Adding both would count overlapping demand twice.

Documentation for max