Write a program to read a list of number from the user and remove the two largest and two smallest values from it. Display the list with removed values , followed by the original list. Your program should generate an appropriate message if the user enters less than 5 values.
Answer to this question:
str_n=input("Enter numbers separated by spaces:")
number_str = str_n.split()
num=[]
ret=[]
if len(number_str)>4:
    for s in number_str:
        num.append(int(s))
    ret=num.copy()
    del_list=num.copy()
    del_list.sort()
    for s in del_list[0:2]+del_list[-2:]:
        ret.remove(s)
    print(ret)
    print(num)
else:
    print("You entered less than five values!")
Comments