Question

Create a program that will determine the even number(s) from a list of numbers. Your program should create and call a functio
0 0
Add a comment Improve this question Transcribed image text
Answer #1

In this problem we have to write a function which returns all the even numbers in a given list in sorted order.

We will use list comprehension to solve this problem. We will add those numbers to our result list which are even.

After this we will sort this list using the sorted() function.

Here's the code.

def findEven(list) :
even_numbers = [num for num in list if num % 2 == 0]
  
return sorted(even_numbers)

list = [1, 1000, 5, -3, 2, 67]

res = findEven(list)

print(res)

_______________________________________

Here are the screenshots of the code and the output.

def findEven (list): even_numbers = [num for num in list if num% 2 - 0] return sorted (even_numbers) list = [1, 1000, 5, -3,

Output [2, 1000]Let me know if you have any doubts in the comments. Please upvote if the answer helped you.

Add a comment
Know the answer?
Add Answer to:
Create a program that will determine the even number(s) from a list of numbers. Your program...
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 Create a program to open a text file for reading, find the maximum number in...

    python Create a program to open a text file for reading, find the maximum number in the file, determine if that maximum number is even, and write to an output text file. You should either write Yes if the number is even, otherwise write the maximum number. You should note the following: • Your input file must be named input.txt • The input file has one integer number per line • Your output file must be named output.txt • Your...

  • 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...

  • Number 1) Which of the following statements imports a module into the default namespace? a. from...

    Number 1) Which of the following statements imports a module into the default namespace? a. from temperature import * b. import temperature as t c. import temperature as temp d. import temperature Number 2) Which of the following statements imports a module into the global namespace? a.from temperature import *   b. import temperature as temp c. import temperature as global d. import temperature Number 3) Code Example 4-2 def get_volume(width, height, length=2):     volume = width * height * length...

  • Write a program that check odd / even numbers (from number 1 to 100). Display the...

    Write a program that check odd / even numbers (from number 1 to 100). Display the results within an HTML table with 2 columns: one for odd number and one for even numbers. NUMBERS RESULTS ODD EVEN ODD 2 HINT: use <table> tags to create a table, <th> tags for 'Numbers' and 'Results'. Wrap code PHP inside HTML code. For example: <html> <title>CHECK ODD or EVEN</title> <body> <table> ?php echo "<tr><td>l</td><td>Odd</td</tr>"; </table> </body </html 2. Do the following steps in...

  • Python 3 Modify the sentence-generator program of Case Study so that it inputs its vocabulary from...

    Python 3 Modify the sentence-generator program of Case Study so that it inputs its vocabulary from a set of text files at startup. The filenames are nouns.txt, verbs. txt, articles.txt, and prepositions.txt. (HINT: Define a single new function, getWords. This function should expect a filename as an argument. The function should open an input file with this name, define a temporary list, read words from the file, and add them to the list. The function should then convert the list...

  • The program defined in insertionSort.cpp gets a list of numbers as input from the user and...

    The program defined in insertionSort.cpp gets a list of numbers as input from the user and calls the insertion sort algorithm to sort them. It also displays the list before and after the sorting. The insertion sort algorithm should be defined in the InsertionSort.h file, but this definition has been omitted and it is your task to provide it. The appropriate insertion sort function is to be defined in the InsertionSort.h file. The InsertionSort.h file performs an include of Swap.h,...

  • Submit a single file named hw0.py that contains the solutions to the problems below. When you...

    Submit a single file named hw0.py that contains the solutions to the problems below. When you are finished, test your solutions using the doctest: copy the file hw0TEST.py from d2l into your working folder. include the following code at the bottom of the module hw0.py, and then run your module.   Fix all failures before you submit your solutions. if __name__=='__main__':     import doctest     print( doctest.testfile( 'hw0TEST.py')) Write a function moreOdds that accepts one argument, a list of integers.   The function then...

  • Need help with Python (BinarySearch), code will be below after my statements. Thank you. Have to...

    Need help with Python (BinarySearch), code will be below after my statements. Thank you. Have to "Add a counter to report how many searches have been done for each item searched for." Have to follow this: 1) you'll create a counter variable within the function definition, say after "the top = len(myList)-1" line and initialize it to zero. 2) Then within the while loop, say after the "middle = (bottom+top)//2" line, you'll start counting with "counter += 1" and 3)...

  • write in python Create a program that will ask the user for a list of integers,...

    write in python Create a program that will ask the user for a list of integers, all on one line separated by a slash. construct a list named "adj_numbers" which contains the users input numbers after subtracting 2 from each number. then print the resulting list. the input statement and print statement are given to you in the starting code. a sample run of the program is as follows: Enter a list of integers, separated by slashes: 7/3/6/8 resulting list:...

  • Create a JAVA program that in two numbers from user input, the program then does the...

    Create a JAVA program that in two numbers from user input, the program then does the following arithmetic calculations. The program will run in ascending order if the first number is small and in descending order of the first number is bigger. The program then alternates between addition(ODD) and subtraction(EVEN) depending on the previous number see examples below   [15] Sample run 1: Enter two numbers: -3 2 Output: The following arithmetic calculations were performed : Arithmetic operations = (-3) +...

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