A caller may prefer an explicit failure when its inputs are invalid. Use raise ValueError(message) to explain a rejected value.
A function can reject an argument before using it. Here the caller catches the exception and displays its message.
def label(gate):
if gate == "":
raise ValueError("gate is missing")
return "Gate " + gate
try:
label("")
except ValueError as error:
print(error) # gate is missingRaising ends the function immediately. The caller decides how to present the problem.
Implement share(total, people) for a nonnegative amount and an integer head count. Return the amount per person for positive head counts. For zero or a negative count, raise ValueError with the exact message people must be positive.
share(9, 2) # 4.5
share(9, 0) # raises ValueError("people must be positive")