Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a program, write function that accepts two arguments: a list, and a number n . Assume that the list contains numbers. The function should

In a program, write  function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all of the numbers in the list that are greater than the number n.

Hints:

Define main ():

                   1.  Declare local variables
                        number = 5
                        number_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

                   2. Display the number.

                   3. Display the list of numbers.

                   4. Display the list of numbers that are larger than the number.

                   5. Call the display_larger_than_n_list function, passing a number and number list as arguments. 

                   6. def display_larger_than_n_list(n, n_list):

                   7.  Declare an empty list.
                   8. Loop through the values in the list.
                  9.  Determine if a value is greater than n. If so, append the value to the list.
                  10. Display the list.

            End main() 

Expected output :

Number: 5
List of numbers:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
List of numbers that are larger than 5:
[6, 7, 8, 9, 10]

Step by Step Solution

3.25 Rating (157 Votes )

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

Starting Out With Java From Control Structures Through Data Structures

Authors: Tony Gaddis

6th Edition

0133957055, 978-0133957051

More Books