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,](http://img.homeworklib.com/questions/86c41d00-84e2-11eb-bd2d-5b064f3f8d1b.png?x-oss-process=image/resize,w_560)
Let me know if you have any
doubts in the comments. Please upvote if the answer helped you.
Create a program that will determine the even number(s) from a list of numbers. Your program...
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 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 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 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 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 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 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 "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, 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:...
o Write a function that outputs even numbers less than the input number. • Function name should be 'evenprint'. • A number is given as input to the function. . The function must return a list of even numbers def evenprint(num): #write statement >[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74,...