Fill This Form To Receive Instant Help
Homework answers / question archive / CS119 Python Programming PJ 12 – List Sorting & Searching Game Please write a Python program that will accept a list of integers (up to 20) from the user into a list, and then show those numbers in ascending order (after being sorted by your sort function), the sum of all integers, and their average
CS119 Python Programming
PJ 12 – List Sorting & Searching Game
Please write a Python program that will accept a list of integers (up to 20) from the user into a list, and then show those numbers in ascending order (after being sorted by your sort function), the sum of all integers, and their average. Then, your program allows the user to search for a number in the list. If the number (from the user) is in the list, please show its index position in the list, otherwise please say the number is not found. To make your program really user-friendly, the index position should start from 1, not 0. Please stop the search game if the user enters -99 as a number to search. Then, you continue to accept another list of integers (up to 20) from the user. Please stop your program with a thank-you message if the user enters zero as the number of integers to play. Please see the sample test below to design your application program properly. This program is like a game of sorting and searching for users to play.
You must write your sort function to sort the integers in the list. You may use any sorting technique to sort the numbers. Please reference chapter 11 of the textbook for some sorting algorithms. For example, the selection sort function is defined on page 406-407, and the bubble sort on page 408.
You must also write your search function to search for the number requested by the user. Please use binary search instead of sequential search technique because the list has been sorted already by your sorting function. Please reference chapter 11 of the textbook for some searching algorithms. For example, the binary search function is defined on page 404 of chapter 11.
You must not call/use the existing lyst.sort( ) method in your program.
You must not call/use the existing lyst.index( target) method to replace binary-search method.
Your test case #1 must look exactly as follows including the data. You must also do test case #2 and test case #3 with different set of data. Each test case must accept at least two lists of integers from the user, and must search at least three numbers for each list. Each test case or test run must begin with a welcome message, and must end with a thank-you message.
Welcome to the List Sorting/Searching Game of "Dr. Simon Lin"! ç must use your name!
1=========================================================.
Please enter how many integers you would like to play (up to 20, 0 to stop) > 5
Please enter number> 2
Please enter number> 5
Please enter number> 3
Please enter number> 4
Please enter number> 1
Your 5 integers in ascending order are: 1 2 3 4 5
Sum is 15, and average is 3
2=========================================================.
Please enter a number to search (-99 to end the search)> 4
The number 4 is found at the position 4
Please enter a number to search (-99 to end the search)> 44
The number 44 is not found.
Please enter a number to search (-99 to end the search)> 1
The number 1 is found at the position 1
Please enter a number to search (-99 to end the search)> -99
3==========================================================.
Please enter how many integers you would like to play (up to 20, 0 to stop) > 6
Please enter number> 9
Please enter number> 20
Please enter number> 5
Please enter number> 3
Please enter number> 34
Please enter number> 18
Your 6 integers in ascending order are: 3 5 9 18 20 34
Sum is 89, and average is 14
4===========================================================.
Please enter a number to search (-99 to end the search)> 34
The number 34 is found at the position 6
Please enter a number to search (-99 to end the search)> 19
The number 19 is not found.
Please enter a number to search (-99 to end the search)> 3
The number 3 is found at the position 1
Please enter a number to search (-99 to end the search)> 20
The number 20 is found at the position 5
Please enter a number to search (-99 to end the search)> -99
5===========================================================.
Please enter how many integers you would like to play (up to 20, 0 to stop) > -99
Please enter how many integers you would like to play (up to 20, 0 to stop) > -4
Please enter how many integers you would like to play (up to 20, 0 to stop) > 0
6===========================================================.
Thank you for playing this List Sorting/Searching Game of "Dr. Simon Lin"!ç must use your name!
7===========================================================.
Python Programming Techniques:
(1) In Python, a list is an array. We cannot create an empty list of size N in Python. However, we can first create an empty list using the following statement for example:
List = [ ] # create an empty list.
Then, we can add a number to the list by using append method. For example, List.append( 7 ) is to add number 7 to the List. Therefore, we can use a for loop to append N numbers to the list.
(2) You must define the following three functions to sort the list and to search a number from the list:
def swap(lyst, i, j): # to swap 2 elements (sub i and sub j ) in the lyst.
def selectionSort ( lyst ): # to sort the lyst. You must not use lyst.sort( ) in your program.
def binarySearch(target, lyst): # to search target number in the lyst, which is an array in Python.
# You must not use lyst.index(target) in your program.
# binarySearch function will return the position that the target
# is in.
(3) You must define the following functions to get the sum and average of all numbers in the list:
def sum( L ): # return the sum of all numbers in the L list
s = 0 # to prepare for the summation of all numbers in the L list
for i in range(len(L)): # i to range thru all members in L list
s += L[i] # add sub i of L to s as accumulation
return s # s is the sum of all integers in the L list
def avg( L ): return ( sum( L )/len( L ) ) # average is sum divided by number of items
# len( L ) function will return the length of L list
(4) You may use the following code to show all numbers in the list L:
for i in range(0, N): # N is the size of list L, N = len(L)
print( L[i], " ", end="" ) # print the list of numbers on the same line
print(" ") # to end this line of showing all integers in list L
=========================================================================.
How to submit your Project Assignment (PJ)?
(1) Each program must be well documented with block comments and proper line comments.
The beginning of each program must have a block comment to show its author, date, and purpose.
The following is an example of block comments:
# Author: _______________ ç must use your full name here!
# Date: _________ ç must put today’s date here!
# Purpose: _______________ ç must show the purpose of this program here!
(2) You must submit to Canvas the following two items as attachments:
(a) Your source program (for example, CS119-PJ12.py ), and
(b) Your WORD document (for example, CS119-PJ12-report .docx ) containing the listing of
your Python program, and the complete output of your 3 test runs as specified.
You must not submit a zip file to Canvas.
=========================================================================.
//You must delete everything above & including this line to make this your Word document to be submitted.
PJ 12 Report My Name: ______________
A. The following is my Python source program:
// Please copy your source program into here from your Visual Studio IDE.
// Your code here must be in color. You must not show screen prints here.
B. The following is the console output of my 3 test runs:
// One way to copy the console output is to press Ctrl+Alt+PrtScn.
// Another way to copy is to use the snipping tool. To paste the image is to press Ctrl+v.
// The console display must not be too wide, otherwise it will be too hard to read once pasted.
// Please make sure your console is long enough to show all your output lines to be captured.
// Please copy your console output and paste into here:
Test Case #1:
Test Case #2:
Test Case #3:
Please download the answer file using this link
https://drive.google.com/file/d/1RYcWCJXQUE4ryxdLXnnCQ_Npuik3qTnY/view?usp=sharing