Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

create functions to complete them IPDS Programming Exercise: January zuzs ############################################################################ This file contains all of the information necessary for completing the exercise. It is

create functions to complete them image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
IPDS Programming Exercise: January zuzs \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# This file contains all of the information necessary for completing the exercise. It is in 4 parts \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#AE\#\#\#\#\#\#E\#\#\#\#\#\#\# Part 1 of the file contains important information in a series of comment boxes (11ke this one) Make sure you read a 11 of Part 1 before proceeding Part 2 contains our program that can be used for testing your code The 'high-level' functions in this program have already been implemented and tested. They call the ones you are required to implement for the exercise, and make use of the values your functiong return. There is no need to change part 2 , but you may do so if you wish to implement your own tests. Part 2 will be removed before marking, so any changes you do make wil1 be lignored by our tester program. Part 3 of the file contains speoifications and code stubs for the functions you are required to implement. For. each of theze functions we have provided For each of these functions we have provided a function header, giving its name and parameter list a set of comments that specify what the function should do a code stub that returns an incorrect value Your job is to provide a body for each function, which implements its specification and returns the correct data value (s) when tested You are not allowed to use any external modules in the solution of these problems (NO IMPORTS) Make sure you do not change any of the function headers Only code that appears in Part 3 will be marked Part 4 currently contains an instruction that runs the main program, which can be used for testing your functions Part 4 will be removed before marking, so any changes you make to it will not be marked WHAT YOU HAVE TO DO You need to revise Part 3 of this file so that each function meets its specification When you have finished you should upload your revised version of the file to Canvas * Please make sure you have inserted your SRN into the code in the manner set out in Part 3 * You may change the name of the file if you wish (we suggest you make frequent backups as well) - You may submit as many times as you like (only your final submission will be marked) - Late submissions cannot be accepted * Late submissions cannot be accepted Your functions will be tested by an automated tester. * Marks are available for each test that is passed * You will get 0 marks for each test that is failed * If your code contains syntax errors it will not be possible to test it, so you may end up with 0 marks for the assignment \#\#\#\#\#\#\# \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#\#\#\#\#\#\#\#F\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# PART 2 : SUR PROGRAM \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# The code in Part 2 will be removed before marking, so any changes you make to the code in this part of the file will not be marked lef Main () : f 'Top-level, function (main program) thelist =[1, Start with an empty list of numbers 1 because the user hasn't entered any yet 1 Main loop - repeatedly displays the menu, gets the user to choose an operation and carries out that operation while True : Showlenu () chosen - GetMenuChoice () if chosen in ["xn,"xn] : 1 option x is 'exit the program' break else: theList - Executechoice (chosen, thelist) print ("Thanks for using the program: goodbye") ShowMenu (): print ("MENU") print ("x Eixit the program") print ("1 Display the current list of numbera") print ("2 hdd numbers to the 11st ) print ("3 Penowe nutbera from the 1idt) print ("4 Clear the 11at of numbers") print ("5 Got the number of odd numbers in ohe liat") print ("6 Get the positione of all. the negative numbers in the 11a th ) print ("7 Get the seadindera after dividing each list elemont by the gamo yhote number") print ("g Get the aigne of all numberd in the 11at ) print ("9 Calcudate the product of al1 positive number" in the 1iat") print ("0 Show the 11at with even numbers removed") print () elif c "7" : divisor = int(input ("Enter a whole number divisor: ")) Showlist (numbers) result = Remainders (numbers, divisor) print ("Whole number remainders are:") print (result) print () elif c= "g" : Showlist (numbers) result = Listofsigns (numbers) print ("Signs of numbers are:") print (result) print () c "g" : Showlist (numbers) result = ProductofPositives (numbers) if result = "999: print ("No positive numbers in the Iist") else : AddNumeToliet (numList) : A gets numbers from the user and adds them to the 7.1st def ShowList (numList) : \# shows a formatted version of numList on screen if numList =[] : print ("The list is empty") else : print ("The current list of numbers is") print (numList) print () \#Xa\#\#\#\#A\#AH\#AHA \#A\#\#AHANA\#HA\#\# DO NOT CHANGE THIS COMMENT BOX: Code from Part 3 will be marked Do not change the 'def' line of any of the functions, or your work may be marked incorrect The pre-condition of each function tells you what data items the function expects as parameters * The function needs to work for any set of data items that makes its preccondition true - Only data items that meet the pre-condition will be used for testing, 30 your function does not need to check whether The post-condition of each function specifies the relationship between the function's parameters and its return value * The function must return a value that makes the post-condition true for any set of data items that makes the pre-condition true You need to write code that implements each of the functions, and test that they do what their specifications say they should You are not allowed to use any external modules in the solution of these problems (NO IMPORTS) IMPORTANT Insert your Student Registration Number (SRN) between the quotation marks in the assignment statement below: SRN =n I. For example, if your SRN is 01234567 the assignment statement is should read SRN = "01234567" if should read SRN = "01234567" fififion 5 (3 marks) dief. Numberofodds (theNums) : A Pre-condition: thenums is a list of whole numbers 1. Post-condition: 1) Returns the number of odd numbers in theNums Numberotoddis ([1,2,3,4,5]) returns 3 Numberofodds ([4,18,0]) returns 0 \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# Option 7 (3 marks) \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# def Remainders (theNums, d) : \# Pre-condition: \# thenums is a list of integers \# d is an integer * Post-condition: * Returns a list containing the remainders obtained when dividing each of the numbers in theNums by d \# Examples: #Remainders([0,1,2,3],3)=[0,1,2,0]####Remainders([1,3,8,7],6)=[1,3,4,5]Remainders([12,14,16,8],3)=[0,2,1,2]Remainders([1,7,2,9],4)=[1,3,2,1]Remainders([1,3,8,7],6)=[5,3,2,1] return None \# Code stub: replace with function body \#\#\#\#\#\# \#\#\# \#\#\# \#\# \#\#\#\#\#\#\#\#\#\#\#\#\#\#\# Option 8 (3 marks) ef Listofsigns (theNums) : \# Pre-condition: theNums is a list of numbers \# Post-condition: Return value is a result list containing strings, each of which indicates the gign (positive, negative of zero) of the number at that position in theNums If the number in position i is positive, result[i] is '+' If the number in position i is negative, result[i] is '-' If the number in position i is zero, result[i] is ' 0 ' Example: Listofsigns ([21,9,0,6]) returns [+,,+] return None \# Code stub: replace with function body \# Option 9 (4 marks) def ProductofPositives (theNums) : * Pre-condition: theNums is a list of numbers \# Post-condition: \# Return value is the product of just the positive numbers in theNums If theNums contains no positive numbers the function should return 999 1 Note: the product of two numbers a and b is a times b return None \# Code stub: replace with function body \#\#\#\#\#\#\#\# \# \#\#\#\#\#\#\#\#\#\#\# \#\# \#\#\#\# Option 0 (4 marks) \#\#\|\# \#\#\#\#\#\#\#\#\#\#\#\# \# \#\# \#\#\#\#\#\# ef RemoveEvensFrom (theNums) : \# Pre-condition: theNums is a list of whole numbers Post-condition: Return value is a list that contains all of the odd numbers that appear in theNums and no other numbers None \#Code stub: replace with function body DO NOT CHANGE THIS COMMENT BOX: WHANHANAHAN it must appear at the end of part 3 in PART 4: Runs the program to test the functions you have implemented You do not need to modify Part 4, but you may do so if you wish to Any code you put in Part 4 will be removed before marking Main() IPDS Programming Exercise: January zuzs \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# This file contains all of the information necessary for completing the exercise. It is in 4 parts \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#AE\#\#\#\#\#\#E\#\#\#\#\#\#\# Part 1 of the file contains important information in a series of comment boxes (11ke this one) Make sure you read a 11 of Part 1 before proceeding Part 2 contains our program that can be used for testing your code The 'high-level' functions in this program have already been implemented and tested. They call the ones you are required to implement for the exercise, and make use of the values your functiong return. There is no need to change part 2 , but you may do so if you wish to implement your own tests. Part 2 will be removed before marking, so any changes you do make wil1 be lignored by our tester program. Part 3 of the file contains speoifications and code stubs for the functions you are required to implement. For. each of theze functions we have provided For each of these functions we have provided a function header, giving its name and parameter list a set of comments that specify what the function should do a code stub that returns an incorrect value Your job is to provide a body for each function, which implements its specification and returns the correct data value (s) when tested You are not allowed to use any external modules in the solution of these problems (NO IMPORTS) Make sure you do not change any of the function headers Only code that appears in Part 3 will be marked Part 4 currently contains an instruction that runs the main program, which can be used for testing your functions Part 4 will be removed before marking, so any changes you make to it will not be marked WHAT YOU HAVE TO DO You need to revise Part 3 of this file so that each function meets its specification When you have finished you should upload your revised version of the file to Canvas * Please make sure you have inserted your SRN into the code in the manner set out in Part 3 * You may change the name of the file if you wish (we suggest you make frequent backups as well) - You may submit as many times as you like (only your final submission will be marked) - Late submissions cannot be accepted * Late submissions cannot be accepted Your functions will be tested by an automated tester. * Marks are available for each test that is passed * You will get 0 marks for each test that is failed * If your code contains syntax errors it will not be possible to test it, so you may end up with 0 marks for the assignment \#\#\#\#\#\#\# \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#\#\#\#\#\#\#\#F\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# PART 2 : SUR PROGRAM \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# The code in Part 2 will be removed before marking, so any changes you make to the code in this part of the file will not be marked lef Main () : f 'Top-level, function (main program) thelist =[1, Start with an empty list of numbers 1 because the user hasn't entered any yet 1 Main loop - repeatedly displays the menu, gets the user to choose an operation and carries out that operation while True : Showlenu () chosen - GetMenuChoice () if chosen in ["xn,"xn] : 1 option x is 'exit the program' break else: theList - Executechoice (chosen, thelist) print ("Thanks for using the program: goodbye") ShowMenu (): print ("MENU") print ("x Eixit the program") print ("1 Display the current list of numbera") print ("2 hdd numbers to the 11st ) print ("3 Penowe nutbera from the 1idt) print ("4 Clear the 11at of numbers") print ("5 Got the number of odd numbers in ohe liat") print ("6 Get the positione of all. the negative numbers in the 11a th ) print ("7 Get the seadindera after dividing each list elemont by the gamo yhote number") print ("g Get the aigne of all numberd in the 11at ) print ("9 Calcudate the product of al1 positive number" in the 1iat") print ("0 Show the 11at with even numbers removed") print () elif c "7" : divisor = int(input ("Enter a whole number divisor: ")) Showlist (numbers) result = Remainders (numbers, divisor) print ("Whole number remainders are:") print (result) print () elif c= "g" : Showlist (numbers) result = Listofsigns (numbers) print ("Signs of numbers are:") print (result) print () c "g" : Showlist (numbers) result = ProductofPositives (numbers) if result = "999: print ("No positive numbers in the Iist") else : AddNumeToliet (numList) : A gets numbers from the user and adds them to the 7.1st def ShowList (numList) : \# shows a formatted version of numList on screen if numList =[] : print ("The list is empty") else : print ("The current list of numbers is") print (numList) print () \#Xa\#\#\#\#A\#AH\#AHA \#A\#\#AHANA\#HA\#\# DO NOT CHANGE THIS COMMENT BOX: Code from Part 3 will be marked Do not change the 'def' line of any of the functions, or your work may be marked incorrect The pre-condition of each function tells you what data items the function expects as parameters * The function needs to work for any set of data items that makes its preccondition true - Only data items that meet the pre-condition will be used for testing, 30 your function does not need to check whether The post-condition of each function specifies the relationship between the function's parameters and its return value * The function must return a value that makes the post-condition true for any set of data items that makes the pre-condition true You need to write code that implements each of the functions, and test that they do what their specifications say they should You are not allowed to use any external modules in the solution of these problems (NO IMPORTS) IMPORTANT Insert your Student Registration Number (SRN) between the quotation marks in the assignment statement below: SRN =n I. For example, if your SRN is 01234567 the assignment statement is should read SRN = "01234567" if should read SRN = "01234567" fififion 5 (3 marks) dief. Numberofodds (theNums) : A Pre-condition: thenums is a list of whole numbers 1. Post-condition: 1) Returns the number of odd numbers in theNums Numberotoddis ([1,2,3,4,5]) returns 3 Numberofodds ([4,18,0]) returns 0 \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# Option 7 (3 marks) \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# def Remainders (theNums, d) : \# Pre-condition: \# thenums is a list of integers \# d is an integer * Post-condition: * Returns a list containing the remainders obtained when dividing each of the numbers in theNums by d \# Examples: #Remainders([0,1,2,3],3)=[0,1,2,0]####Remainders([1,3,8,7],6)=[1,3,4,5]Remainders([12,14,16,8],3)=[0,2,1,2]Remainders([1,7,2,9],4)=[1,3,2,1]Remainders([1,3,8,7],6)=[5,3,2,1] return None \# Code stub: replace with function body \#\#\#\#\#\# \#\#\# \#\#\# \#\# \#\#\#\#\#\#\#\#\#\#\#\#\#\#\# Option 8 (3 marks) ef Listofsigns (theNums) : \# Pre-condition: theNums is a list of numbers \# Post-condition: Return value is a result list containing strings, each of which indicates the gign (positive, negative of zero) of the number at that position in theNums If the number in position i is positive, result[i] is '+' If the number in position i is negative, result[i] is '-' If the number in position i is zero, result[i] is ' 0 ' Example: Listofsigns ([21,9,0,6]) returns [+,,+] return None \# Code stub: replace with function body \# Option 9 (4 marks) def ProductofPositives (theNums) : * Pre-condition: theNums is a list of numbers \# Post-condition: \# Return value is the product of just the positive numbers in theNums If theNums contains no positive numbers the function should return 999 1 Note: the product of two numbers a and b is a times b return None \# Code stub: replace with function body \#\#\#\#\#\#\#\# \# \#\#\#\#\#\#\#\#\#\#\# \#\# \#\#\#\# Option 0 (4 marks) \#\#\|\# \#\#\#\#\#\#\#\#\#\#\#\# \# \#\# \#\#\#\#\#\# ef RemoveEvensFrom (theNums) : \# Pre-condition: theNums is a list of whole numbers Post-condition: Return value is a list that contains all of the odd numbers that appear in theNums and no other numbers None \#Code stub: replace with function body DO NOT CHANGE THIS COMMENT BOX: WHANHANAHAN it must appear at the end of part 3 in PART 4: Runs the program to test the functions you have implemented You do not need to modify Part 4, but you may do so if you wish to Any code you put in Part 4 will be removed before marking Main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions