Question

In: Computer Science

Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Task 2...

Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested.

Task 2

Please define a function that extracts the even numbers in a given list. For example, given a list x = [2,3,5,6,7], the function will return a sublist [2,6] because 2 and 6 are even numbers in the list x.

The input of this function should be a list, and the output of the function should be a list as well (the sublist).

You can try the inline for loop with conditions to make the solution super simple.

Task 3

Use inline for loop to extract the common elements in two lists. For example, if x = [1,2,3], and y = [2,3,4], the result should be [2,3].

Hint: to check if a value exists in a list, you can use the “in” command. For example: we define two variables

a = 2 in [1,2,3]

b = 4 in [1,2,3].

After executing the codes, a will be a “True”, and b will be a “False”.

Solutions

Expert Solution

Answer 1:

def evenList(myList):

res=[]

#iterating throught list

for x in myList:

#checking if even than adding to new list

if x%2==0:

res.append(x)

#returning new list

return res

print(evenList([2,3,5,6,7]))

Answer 2:

def commonList(list1,list2):

res=[]

#iterating throught list

for x in list1:

#checking if element exist in list2 than adding to new list

if x in list2:

res.append(x)

#returning new list

return res

print(commonList([2,3,5,6,7],[2,3,4,7,9]))

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Task 2...
Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Task 2 We are producing two types of products, product A and product B. Product A is defective if the weight is greater than 10 lbs. Product B is defective if the weight is greater than 15 lbs. For a given product, we know its product_type and its weight. Design a program to screen out defective products. Starting the program with variable definition: product_type = 'xxx'...
Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Given two...
Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Given two exam scores, exam_1 and exam_2, write a program to determine if the student makes progress (exam_2 is greater than exam_1). Return “Yes” or “No”. You can use any exam_1 score and exam_2 score for this exercise.
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to...
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to print the type of the following variables. Please write down the codes and the output as well. x = 3.5 y = '3.5' z = {1:'John', 2:'Wick', 3:'Barry', 4:'Allen'}
Please attach to the application a brief narrative outlining your academic interests. Include any current or...
Please attach to the application a brief narrative outlining your academic interests. Include any current or long-range interests in research, teaching or other professional objectives. If you have progressed far enough in your career to have publications or other evidence of scholarly endeavor, please describe these. plzzz ans asap...
Please write the program in JAVA and provide me with the output screenshots!! Assignment Objectives •...
Please write the program in JAVA and provide me with the output screenshots!! Assignment Objectives • Be able to write methods • Be able to call methods Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct...
Python 3! Please provide detailed information and screenshots! This is a practice for you to discuss...
Python 3! Please provide detailed information and screenshots! This is a practice for you to discuss an implementation of a BST (Binary Search Tree) in a real-life scenario or real business scenario. What to submit? 1. An introduction with a title of what is the implementation 2. A diagram or design of how the BST is implemented in your scenario 3. Simple explanation of the implementation 4. Can you make it as an application in Python. Yes/No. If Either Yes...
Java and please have screenshots with source code and output \item[(1)] A palindrome is a string...
Java and please have screenshots with source code and output \item[(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as...
TASK: ( answers should be computerized and in details - please do not copy and paste...
TASK: ( answers should be computerized and in details - please do not copy and paste - about 1500 words ) Select an organization of your choice and carry out the following tasks. Conduct a research on the marketing and promotional strategies of the organization selected. Your Report should include the following: 1. Introduction 2. Summarize the various promotional strategies used by the organization in implementing an Integrated Marketing Strategy. Identify the risks associated with promotional campaigns and discuss how...
USE Python 2.7(screen shot program with output) the task is: takes in a list of protein...
USE Python 2.7(screen shot program with output) the task is: takes in a list of protein sequences as input and finds all the transmembrane domains and returns them in a list for each sequence in the list with given nonpolar regions and returns the lists for those. 1. This code should call two other functions that you write: regionProteinFind takes in a protein sequence and should return a list of 10 amino acid windows, if the sequence is less than...
Please in C++, show screenshots of output plus .txt file. thanks Breakfast Billing System Write a...
Please in C++, show screenshots of output plus .txt file. thanks Breakfast Billing System Write a program to help a local restaurant automate its breakfast billing system. The program should do the following: Show the customer the different breakfast items offered by the restaurant. Allow the customer to select more than one item from the menu. Calculate and print the bill Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT