Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement a Python function called count_pos that takes a list of numbers as an input parameter and returns the num- ber of elements of that
Implement a Python function called count_pos that takes a list of numbers as an input parameter and returns the num- ber of elements of that list that are positive (i.e. > 0). Then, in the ma in, your program should ask the user to input the list, then it should call count_pos function with that list, and print the result. In this question you may assume that the user will follow your instructions and enter a sequence of numbers separated by spaces. You can use str method .strip and .split to handle the user input. Here is a way to ask a user for a list: raw-input = input ("Please inpu t a list of numbers separated by space : ").strip() . split() But now raw-input is a list of strings that look like numbers so you need to create a new list that is a list of equivalent numbers. Three examples of program runs: Please input a list of numbers separated by space: 2 3.5-1-100 There are 2 positive numbers in your list Please input a list of numbers separated by space: 1 0 2201 There are 3 positive numbers in your list Please input a list of numbers separated by space: There are 0 positive numbers in your list Function call example: >countpos( 11, 0, 22.2, 0, 1.0, -10.51
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started