Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What extra info is required? IPDS Programming Exercise: January 2023 ########################################################################## This file contains all of the information necessary for completing the exercise. It is

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
image text in transcribed
What extra info is required?
IPDS Programming Exercise: January 2023 \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# This file contains all of the information necessary for completing the exercise. It is in 4 parts \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#\#\#A\#\#\#A\#\#\#\#\#\#\#A\# Part 1 of the file contains important information in a serles of comment boxes (11ke this one) Make sure you read all of Part 1 before proceeding Part 2 containg our program that can be used for testing your code The 'high-level' functions in thig 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 functions return. There is no need to change part:2, but you may do so if you wish to imploment your own tests. Part 2 will be removed before marking, so any changes you do make wil1 be ignored by our tester program. Part 3 of the file contains specifications and code stubs for the functions you are required to implement. For each of these 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 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 () : 1 Main loop - repeatedly dieplays the monu, gets the user to choose an operation and carries out that operation while True : Showluenu () chosen = GetMenuChoice () 11 chosen in ["x,"x=] i option x is 'exit the program' e 1 me: theList = ExecuteChoice (chosen, theList) print ("Thanks for using the programi goodbye") Siet Showhenu () : GetMenuChoice () : \# Gets a menu choice from the user and returns it choice = input ("Please enter a choice from the menu:") print() return choice def ExecuteChoice (c, numbers) : \# performs the operation specified by c on the list called numbers if c== " 1" : \# Display the current list of numbers ShowList (numbers) elif c="2":= Add numbers to the list ShowList (numbers) print ("Add numbers to the list") numbers = AddNumsToList (numbers) ShowList (numbers) elif c="3":# Remove numbers from the list ShowList (numbers) print ("Remove numbers from the list") numbers = RemoveNumsFromList (numbers) ShowList (numbers) elif c==4":$ Clear the list of numbers numbers =[] Showlist (numbers) elif c==5" : Showlist (numbers) result = Numberofodds (numbers) print ("Count of odd numbers is ", result) print () elif c==6" : Showlist (numbers) result = Positionsofinegs (numbers) print ("Negative numbers are in positions:") print (result) print () elif c== " c ": divisor = int(input ("Bnter a whole number divisor: ")) Showlist (numbers) result = Remainders (numbers, divisor) print ("Whole number remainders are:") 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= c g : ShowList (numbers) result = Listofsigns (numbers) print ("Signs of numbers are:") print (result) print () elif c= "g": ShowList (numbers) result = ProductofPositives (numbers) if result =999 : print ("No positive numbers in the list") else : print ("Product of positive numbers is ", result) print () elif c= "on: Showlist (numbers) result = RemoveEvensfrom (numbers) print ("List without even numbera:") print (result) print () else : print ("Option", c, "not on menu") return numbers AddNumeToliet (numList) : A gets numbers from the user and adds them to the 11st numste = input ("PIease type fri p Whole number, or g to quit:" ") def ShowList (numList) : \# shows a formatted version of numList on screen if numbist =[] : print ("The list is empty") else : print ("The current list of numbers is") print (numList) print () 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 expectis as parameters + The function needs to wor - Only preccondition true for testing, so your meet the pre-condition will be used the pre-condition has been mot. The post-condition of each function specifies the relationship between the function' 9 parameters and its return value * The function must return a value that makes the post-condition true for any get 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 if should read SRN = "01234567" if should read SRN= "01234567" foption 5 (3 marks) def. Numberofodds (theNums) : 1. Pre-condition: f. thenumg is a list of whole numbers - Post-condition: A Returns the number of odd numbers in theNums Numberofodds ([1,2,3,4,5]) returns 3 Numberofodds ([4,18,0]) returns 0 Option 6 (3 marks) \#\#\#\#\#\# \#\#\#\#\#\#\#\#\#\#\# n \#\#\# \# \#\#\# PositionsofNegs (theNums) : * Pre-condition: * theNums is a list of numbers Post-condition: Returns a list containing the positions of all of the negative numbers in theNums Examples: PositionsofNegs ([1,2,3,4,5]) returns [2,4] PositionsofNegs ([4,7,18]) returns [] Positionsofnegs ([0,3,5,9,17]) returns [1,2,3,4] return None \# Code stub: replace with function body \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# 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 ([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] Remainders ([1,3,8,7],6)=[1,3,4,5] 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 sign (positive, negative or 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 'o' Example: Listofsigns ([21,9,0,6]) returns [+,,,0,+] 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 - 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) lef 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 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

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions