Robotics & Artificial Intelligence
Write a function which deletes all the negative values from a list passed as an argument.
Python Functions
1 Like
Answer
def remove_negative(lst):
new_list = []
for x in lst:
if x >= 0:
new_list.append(x)
return new_list
numbers = eval(input("Enter list: "))
result = remove_negative(numbers)
print(result)Output
Enter list: [2, -5, 6, -3, 0, 8]
[2, 6, 0, 8]
Answered By
2 Likes
Related Questions
Write a function which returns if a number passed as as argument is a perfect number or an Armstrong number.
Write a function which returns if a number passed as an argument is a prime or composite number.
Write a function which counts and displays the number of vowels, consonants, uppercase, and lowercase characters in a string entered as input.
Write a function which takes a number and a list as arguments and counts the occurrence of that number in the given list.