Question

In: Computer Science

IN PYTHON PLEASE Create a file lists.py that contains the following functions: sumOfOdd(intList) The parameter intList...

IN PYTHON PLEASE

Create a file lists.py that contains the following functions:

sumOfOdd(intList)

  • The parameter intList is supposed to be a list of integers.
  • The function returns the sum (addition) of the odd integers from intList, and leaves intList not modified
  • For instance, given [1,2,3,4], the function returns 4.
  • The function performs no I/O.

productOfEven(intList)

  • The parameter intList is supposed to be a list of integers.
  • The function returns the product (multiplication) of the even integers from intList, and leaves intList not modified.
  • For instance, given [1,2,3,4], the function returns 8.
  • The function performs no I/O.

evenMembers(intList)

  • The parameter intList is supposed to be a list of integers.
  • The function returns a new list containing the even integers from intList, in the same order, and leaves intList not modified.
  • For instance, given [1,2,3,4,2,3,6], the function returns [2,4,2,6].
  • The function performs no I/O.

changeList(intList)

  • The parameter intList is supposed to be a list of integers.
  • The function modifies intList:
    • For odd integers one (1) is added and then the result is divided by 2
    • Even integers are multiplied by 3.
  • This function does not return anything. (void)
  • For instance, the parameter [1,2,3,4]  should become [1,6,2,12].
  • The function performs no I/O.

isReverse(intListOne, intListTwo)

  • The parameters intListOne and intListTwo are supposed to be lists of integers.
  • The function will return true if intListTwo is the reversed version of intListOne.
  • The function will return false if intListTwo is NOT the reversed version of intListOne.
  • The function performs no I/O.

Solutions

Expert Solution

def sumOfOdd(intList):
oddSum=0
for i in range(0,len(intList),1):
if(intList[i]%2!=0):
oddSum=oddSum + intList[i]
print("oddSum=",oddSum)
def productOfEven(intList):
productEven=1
for i in range(len(intList)):
if(intList[i]%2==0):
productEven = productEven * intList[i]
print("product EVen=",productEven)
def evenMembers(intList1):
listt=[]
for i in range(len(intList1)):
if(intList1[i]%2==0):
listt.append(intList1[i])
print("change of even num to another list=",listt)
print("original list=",intList1)
def changeList(intList):
for i in range(len(intList)):
one=1
if (intList[i]%2 == 0):
intList[i]=(intList[i] * 3)
if(intList[i]%2 !=0):
intList[i]=intList[i]+one
intList[i]=int(intList[i]/2)
print("change of current list=",intList)

def isReverse(intListOne, intListTwo):
intListOne.reverse()
if(intListOne == intListTwo):
return True
else:
return False
  
intList=[1,2,3,4]
intList1=[1,2,3,4,2,3,6]
b=[1,2,3,4]
c=[4,3,2,1]
sumOfOdd(intList)
productOfEven(intList)
evenMembers(intList1)
changeList(intList)
a=isReverse(b,c)
print("reverse check=",a)

regarding any concerns about above code please mention in comments thankyou


Related Solutions

Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching...
Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching pairs of vehicle models and their respective makes Separate out the individual make and model on each line of the file Add the vehicle make to one list, and the vehicle model to another list; such that they are in the same relative position in each list Prompt the user to enter a vehicle model Search the list containing the vehicle models for a...
Python: Trivia Questionaire Create a trivia application using the provided file which contains 15 questions in...
Python: Trivia Questionaire Create a trivia application using the provided file which contains 15 questions in it. Your application should randomly select how many questions will be presented to the user and it must be a number not greater than the number of questions in the file. Every question that is displayed should be randomly selected from the list and should be non-repetitive; in other words, you should not ask the same question twice. Your application should keep track of...
[In Python] Write a program that takes a .txt file as input. This .txt file contains...
[In Python] Write a program that takes a .txt file as input. This .txt file contains 10,000 points (i.e 10,000 lines) with three co-ordinates (x,y,z) each. From this input, use relevant libraries and compute the convex hull. Now, using all the points of the newly constructed convex hull, find the 50 points that are furthest away from each other, hence giving us an evenly distributed set of points.
On Python Write a function that accepts a relative file path as parameter and returns number...
On Python Write a function that accepts a relative file path as parameter and returns number of non-empty lines in the file. Test your function with the provided sample file studentdata.txt.
Using Python. A file exists on the disk named students.txt. The file contains several records, and...
Using Python. A file exists on the disk named students.txt. The file contains several records, and each record contains two fields: (1) the student’s name, and (2) the student’s score for the final exam. Write code that deletes the record containing “John Perz”as the student name. This the code i have so far but it's not working: import os def main(): found=False search='John Perz' student_file = open('student.txt','r') temp_file = open('temp_students.txt','w') name=student_file.readline() score='' while name !='': score=student_file.readline() name=name.rstrip('/n') score=score.rstrip('/n') if name...
USE PYTHON Create a single list that contains the following collection of data in the order...
USE PYTHON Create a single list that contains the following collection of data in the order provided: [1121, "Jackie Grainger", 22.22, 1122, "Jignesh Thrakkar", 25.25, 1127, "Dion Green", 28.75, False, 24.32, 1132, "Jacob Gerber", "Sarah Sanderson", 23.45, 1137, True, "Brandon Heck", 1138, 25.84, True, 1152, "David Toma", 22.65, 23.75, 1157, "Charles King", False, "Jackie Grainger", 1121, 22.22, False, 22.65, 1152, "David Toma"] The data above represents employee information exported from an Excel spreadsheet. Whomever typed the data in originally didn't...
in C++ (Please do steps 1-11) 1 ) Create a file that contains your grades and...
in C++ (Please do steps 1-11) 1 ) Create a file that contains your grades and the type of assement (you can just create the file or write the file in the program) A = Assignment E = Extra Credit L - Lab Q = Qui M = Mid Example: L 20 L 20 L 20 Q 10 A 18 E 9 Q 10 L 20 Q 10 L 20 Q 10 L 20 M 85 2 ) create 3...
in python please Q1) Create a Singly link list and write Python Programs for the following...
in python please Q1) Create a Singly link list and write Python Programs for the following tasks: a. Delete the first node/item from the beginning of the link list b. Insert a node/item at the end of the link list c. Delete a node/item from a specific position in the link list Q2) Create a Singly link list and write a Python Program for the following tasks: a. Search a specific item in the linked list and return true if...
In IDLE - Python 3, do the following: 1. Create File --> New 2. Enter the...
In IDLE - Python 3, do the following: 1. Create File --> New 2. Enter the code below in the new file (you may omit the comments, I included them for explanation #Python Code Begin x = int(input("Enter a number: ")) y = int(input("Enter another number: ")) print ("Values before", "x:", x, "y:", y) #add code to swap variables here #you may not use Python libraries or built in swap functions #you must use only the operators you have learned...
In a header file Record.h, create a Record structure that contains the following information: recordID, firstName,...
In a header file Record.h, create a Record structure that contains the following information: recordID, firstName, lastName, startYear. recordID is an integer. In testRecord, first create a record (record1) using “normal” pointers. Set the values to 1001, Fred, Flintstone, 1995 In testRecord, create a new record (record2) using a unique smart pointer. Set the values to 1002, Barney, Rubble, 2000 Create a function (or functions) that will print the records to any output stream. Since the print function does not...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT