Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What are the best practices for managing a large software project?

Answered: 1 week ago

Question

How does clustering in unsupervised learning help in data analysis?

Answered: 1 week ago