write me python program that recieves a list of numbers from input and identifies and…
- User
write me python program that recieves a list of numbers from input and identifies and prints the second maximum number
- Assistant
Sure! Here's a Python program that receives a list of numbers from input and identifies and prints the second maximum number:
num_list = input("Enter a list of numbers (space-separated): ").split() num_list = list(map(int, num_list)) if len(num_list) < 2: print("Please enter at least two numbers.") else: max_num = max(num_list[0], num_list[1]) second_max_num = min(num_list[0], num_list[1]) for num in num_list[2:]: if num > max_num: second_max_num = max_num max_num = num elif num > second_max_num and num != max_num: second_max_num = num print("The second maximum number is:", second_max_num)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.