Question

In: Computer Science

11. First and Last Design a program that asks the user for a series of names...

11. First and Last Design a program that asks the user for a series of names (in no particular order). After the final person's name has been entered, the program should display the name that is first alphabetically and the name that is last alphabetically. For example, if the user enters the names Kristin, Joel, Adam, Beth, Zeb, and Chris, the program would display Adam and Zeb.

#Sentinel value is DONE
SENTINEL = "DONE"
ls = []

prompt = "Enter a name, or enter DONE to quit."

newLs = input(prompt)

n = newLs

#test for sentinel
while newLs != SENTINEL:
ls.append(newLs)
newLs = input(prompt)
#sort in alphabetical
for i in range(n) :
name = int()
ls.append(name)
ls.sort()

print('{} and {}'. format(ls[0],ls[n-1]))
I need help with sorting the names from the sentinel loop so that I get only two outputs that are alphabetically ordered

Solutions

Expert Solution

As per your requirement, here is the Python code:

Rawcode:

#Sentinel value is DONE

SENTINEL = "DONE"

#creating a list to store the names

ls = []

#prompt variable which stores the string that says enter a name or enter done to quit

prompt = "Enter a name, or enter DONE to quit."

#prompting user for input name

newLs = input(prompt)

#while loop whcih runs until user enters DONE

while newLs != SENTINEL:

    #appending each input name to the list

    ls.append(newLs)

    #keep on asking the user to enter the input name until user enters DONE

    newLs = input(prompt)

#sort in alphabetical

ls.sort()

#as the list is sorted we have to print the first value of list and last value of list

#first value can accessed by using index value 0 and last value can be accessed by subtracting one from lenght of list

print('{} and {}'. format(ls[0],ls[len(ls) - 1]))

Here is the screenshot of source code:

Here is the screenshot of output:

Hope this helps you. Please feel free to ask if you still have any queries.

Do upvote. Thank you !


Related Solutions

Design a complete program that asks the user to enter a series of 20 numbers. The...
Design a complete program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display each of the following data: I. The lowest number in the array II. The highest number in the array III. The total of the numbers in the array IV. The average of the numbers in the array *PYTHON NOT PSUEDOCODE AND FLOW CHART!!!!*
Create a program that asks the user for the names of two car dealerships and the...
Create a program that asks the user for the names of two car dealerships and the # of cars sold in each one. Then output that data in two columns as shown below. The "Store location" column has a width of 25, while the "Cars sold" column has a width of 9. Also, notice the alignment of the second column. The program should end with the "Press Enter to end this program" prompt. OUTPUT Enter the location for the first...
Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
Design a program that asks the user for a number and the program computes the factorial...
Design a program that asks the user for a number and the program computes the factorial of that number and displays the result . Implement with two different modules - one that uses a for loop and one that uses a while loop Grading Rubrick Program Compiles Cleanly  syntax errors25 pts-5 per errorProgram runs without runtime errors ( validation)run-time errors 25 pts-5 per errorProgram give correct answersLogic errors30 pts-5 per errorProgram is repeatableNot repeatable5 pts-5 ptsProgram is well modularizedBarely Modularized10 pts-...
Number Analysis Program (Specific Design Specifications) Design a Python program that asks the user to enter...
Number Analysis Program (Specific Design Specifications) Design a Python program that asks the user to enter a series of 20 numbers. The program should store the numbers in a list then display the following data: The lowest number in the list The highest number in the list The total of the numbers in the list The average of the numbers in the list This python program must include the following functions. Your program must use the exact names, parameter lists,...
Write a program that asks the user for a file name. The file contains a series...
Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in the array 5)...
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
Write a C++ program that asks the user to enter a series of single-digit numbers with...
Write a C++ program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program should display the sum of all the single-digit numbers in the string. For example, if the user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string. It is...
Using Pseudocode: Design a program that allows the user to enter 20 names into a String...
Using Pseudocode: Design a program that allows the user to enter 20 names into a String array. Sort the array in ascending (alphabetical) order and display its contents.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT