Answer to Question #349973 in Python for Pathan

Question #349973

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.




1
Expert's answer
2022-06-13T08:27:11-0400

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!")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS