Question: 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

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 Programming Questions!