Write a Python program that continually asks the user for numbers until the user enters ‘stop’. The program should then output the maximum and minimum numbers entered.
Example 1:
Input: numbers = 5, 2, 9, 1, 'stop' Output: Max = 9, Min = 1
Example 2:
Input: numbers = 7, 8, 10, 3, 4, 'stop' Output: Max = 10, Min = 3
Initialize variables max
and min
to None
. In a while loop, update max
and min
based on the input numbers.
max, min = None, None while True: num = input("Enter a number (or 'stop' to finish): ") if num == 'stop': break num = int(num) if max is None or num > max: max = num if min is None or num < min: min = num print("Max =", max, "Min =", min)
Unlock AI & Data Science treasures. Log in!