Code:
def find_max_min(numbers):
# Check if the list is not empty
if len(numbers) == 0:
return None, None
# Find the maximum and minimum numbers
maximum = max(numbers)
minimum = min(numbers)
return maximum, minimum
# Example usage
user_input = input("Enter a list of numbers separated by spaces: ")
# Convert the input string to a list of floats
numbers_list = [float(x) for x in user_input.split()]
# Find the maximum and minimum numbers and display the result
max_num, min_num = find_max_min(numbers_list)
if max_num is not None and min_num is not None:
print(f"The maximum number in the list is: {max_num}")
print(f"The minimum number in the list is: {min_num}")
else:
print("The list is empty.")
Output:
No comments:
Post a Comment