Question: (Python) Write the function num_negatives() that takes as input a list of numbers and returns the number of negatives in the list. Write the function

(Python) Write the function num_negatives() that takes as input a list of numbers and returns the number of negatives in the list. Write the function negatives() that takes as input a list of numbers and returns a list of only the negative numbers in the list.

Sample runs are shown below.

Sample 1 Enter some numbers separated by whitespace 2.3 -9.8 5 6.7 -12 3 The number of negatives in the list is 2 The negatives in the list are -9.8 -12.0

Sample 2 Enter some numbers separated by whitespace 1 2 3 4 5 -6 7 -8 9 -12.7 The number of negatives in the list is 3 The negatives in the list are -6.0 -8.0 -12.7

Sample 3 Enter some numbers separated by whitespace 1 2 3 The number of negatives in the list is 0 The negatives in the list are

# function definition - given the parameter theList, return the count of negative numbers in the list

def num_negatives(theList):

# add the necessary code

# function definition - given the parameter theList, return a list that contains only the negative numbers in the parameter list

def negatives(theList):

# add the necessary code

# prompt the user to enter a list of numbers and store them in a list

list = [float(x) for x in input('Enter some numbers separated by whitespace ').split()]

print()

# output the number of negatives

print('The number of negatives in the list is', num_negatives(list))

print()

# output the list of negatives numbers

print('The negatives in the list are ', end = '')

for items in negatives(list):

print(items, ' ', sep = '', end = '')

print(' ')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!