Question

PYTHON CODE

In a program, write a 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. Output should look like:

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]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As per your request, I have created this Python program. If you're copying the program, make sure to have the same indents as mine or you might encounter errors.

Here is the code:

n = int(input("Number:"))# accepts input from user
listofnumbers = [int(x) for x in input("List of numbers:").split()]# accepts list from user
listgreaterthann = []# empty list to feed numbers greater than input in listofnumbers
for x in listofnumbers:# for loop
if x > n and x not in listgreaterthann:
listgreaterthann.append(x)# appends number that are greater than 'n'
print("List of number that are larger than ", n, "are:") # prints the list of number larger than 'n'
for x in listgreaterthann: # This for loop prints all the number in the the list 'listgreaterthann'
print(x)# prints everthing in list

- n = lè sssss.py - C:/Users/ns200/Desktop/sssss.py (3.7.4) File Edit Format Run Options Window Help int(input (Number:))#Here is the output:

RESTART: C:/Users/ns200/Desktop/sssss.py Number: 5 List of numbers:1 2 3 4 5 6 7 8 9 10 List of number that are larger than 5


First of all, this program accepts input 'n' from the user. This input will be used as a base to check what numbers are greater than it. Then we will have our list of numbers sumbitted by the user ( as requested by you) which will be stored in 'listofnumbers'.

This command "[int(x) for x in input("List of numbers:").split()]" is used to take input from the user as a list.

Further, we'll create an empty list to store values later which will be greater than the user input 'n'.
We'll create a 'for loop' that will determine whether a number will fit into the list. If it already exists in the list, the program will skip that number and only append the number which aren't there.

"print("List of number that are larger than ", n, "are:")" will prints the total elements greater than 'n'.

The for loop at the end prints all the values in 'listgreaterthann'

If you have any doubts, leave a comment below before rating. I'll happy to assist you further.

Do upvote this if it helped you. Thank you

Add a comment
Know the answer?
Add Answer to:
PYTHON CODE In a program, write a function that accepts two arguments: a list, and a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python In a program, write a function that accepts two arguments: a list, and a number...

    python In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display the number n, the list of numbers, and a sub list of all the numbers in the list that are greater than the number n. Initialize the list and the number n in the main function of your code and call your function, passing the list and number as arguments. Run your code...

  • Write in C++ program Larger than n In a program, write a function that accepts three...

    Write in C++ program Larger than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n. Input from the keyboard: The filename and path of a list of integer numbers.                                           The number n to test the file numbers. Output to the console: The...

  • PYTHON: Using Lists and Arrays! 5. In a program, write a function that accepts two arguments:...

    PYTHON: Using Lists and Arrays! 5. In a program, write a function that accepts two arguments: a list, and a number n. The program should generate 20 random numbers, in the range of 1 through 100, and assign each number to the list. The program should also ask the user to pick a number from 1 through a 100 and assign that number to n. The function should display all of the number in the list that are greater than...

  • Phyton In a program, write a function that accepts two arguments: a list, and a number...

    Phyton In a program, write a 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 smaller than the number n.

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • in a program, write a function that accepts three arguments: an array, the size of the...

    in a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n.

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Design a function named max that accepts two integer values as arguments and returns the value...

    Design a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Need Variable lists, Psuedocode, ipo chart, Flow Chart, and a python...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT