Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use python to write those questions Question 1: ===================== Implement a Python function called count_pos that takes a list of numbers as input (parameter) and

use python to write those questions

Question 1:

=====================

Implement a Python function called count_pos that takes a list of numbers as input (parameter) and returns the number of

elements of that list that are positive (> 0). Then, in the main portion of your program should ask the user to input the list, then it

should call count_pos function with that list, and print the result. You may assume that the user will always enter at least two

elements, but your function count_pos should work for all lists of numbers including those of length 0 and 1.

Examples of program runs:

Example 1:

Please input a list of numbers separated by commas: 1,2,0,3,0,4

There are 4 positive numbers in your list.

Example 2:

Please input a list of numbers separated by commas: 1,2,9

There are 2 positive numbers in your list.

Here is a way to ask a user for a list:

s = input("Please input a list of numbers separated by commas: ")

L = list(eval(s))

If a user enters at least two numbers separated by commas, variable L will refer to that list.

=====================

Question 2:

=====================

A run is a sequence of consecutive repeated values. Implement a Python function called two_length_run that takes a list of

numbers as input and returns True if the given list has is at least one run (of length at least two), and False otherwise. Make

sure the function is efficient (i.e. it stops as soon as the answer is known). Then, in the main, your program should ask the user

to input the list, then it should call two_length_run function, and print the result. You may assume that the user will always

enter at least two elements, but your function two_length_run should work for all lists of numbers including those of length 0

and 1.

Examples of program runs:

Example 1:

Please input a list of numbers separated by commas: 1,4,3,3,4

True

Example 2:

Please input a list of numbers separated by commas: 1,2,3,3,3,4,6,5

True

Example 3:

Please input a list of numbers separated by commas: 1,2,3,4,3,2

False

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

Logics For Databases And Information Systems

Authors: Jan Chomicki ,Gunter Saake

1st Edition

1461375827, 978-1461375821

More Books

Students also viewed these Databases questions