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.
I need help with creating a python code for this using a sentinel loop
Code:
n = int(input('Enter the number of names : '))
ls = []
for i in range(n):
name = input()
ls.append(name)
ls.sort()#sorting the list based on names
#printing the output:
print('{} and {}'.format(ls[0],ls[n-1]))
Output:
Code screenshot:
Get Answers For Free
Most questions answered within 1 hours.