Examining the List for the Maximum
(Menu) A B C D E F G H I
The normal code is put in a try() block.
maxFloat() is set to the first number in the list.
All the other items are inspected. Any higher value replaces maxFloat().
If the search for a maximum fails for any reason()
myFloats = [4.5, 2.6, 3.8, 3.5, 1.0, 5.7]
try:
maxFloat = myFloats[0]
for item in myFloats:
if item > maxFloat:
maxFloat = item
print("Maximum is", maxFloat)
except:
print("Maximum is undefined.")
5.7
an exception is raised and reported but the program doesn't crash.