Finding Maximum and Minimum from User Input

Category: Python Basics

Write a program that asks the user to input a list of integers and then outputs the maximum and minimum of the list.


Input: [3, 1, 4, 1, 5, 9, 2, 6] 

Output: Max: 9, Min: 1

Input: [5, 5, 5, 5] 

Output: Max: 5, Min: 5

You can use built-in functions like max() and min() or iterate through the list to find the maximum and minimum values.

numbers = list(map(int, input("Enter a list of integers separated by space: ").split()))
max_num = max(numbers)
min_num = min(numbers)
print(f"Max: {max_num}, Min: {min_num}")

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!