if statements to determine the minimum value, then displays it.# fig02_02.py
"""Find the minimum of three values."""
number1 = int(input('Enter first integer: '))
number2 = int(input('Enter second integer: '))
number3 = int(input('Enter third integer: '))
minimum = number1
if number2 < minimum:
minimum = number2
if number3 < minimum:
minimum = number3
print('Minimum value is', minimum)
12, 27 and 36run fig02_02.py
12, 36 and 27run fig02_02.py
36, 27 and 12run fig02_02.py
number1 contains the smallest value. if statement then tests number2 < minimum and if this condition is True assigns number2 to minimum. if statement then tests number3 < minimum, and if this condition is True assigns number3 to minimum. minimum contains the smallest value, so we display it. min and max (1 of 2)¶min and max calculate the minimum and maximum, respectively, of a collection of values.min and max (2 of 2)¶min(36, 27, 12)
max(36, 27, 12)
min and max are examples of a functional-style programming concept called reduction—each reduces a collection of values to a single value. ©1992–2020 by Pearson Education, Inc. All Rights Reserved. This content is based on Chapter 2 of the book Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud.
DISCLAIMER: The authors and publisher of this book have used their best efforts in preparing the book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in these books. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.