Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a Python program that will accept a list of integers (up to 20) from the user into a list , and then show

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. 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. You may reference chapter 11 of the textbook for some sorting and searching algorithms. For example, the selection sortfunction is defined on page 406-407, and the bubble sort on page 408. 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===========================================================.

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

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago