Docsity

Coding python computer science, Schemes and Mind Maps of Computer science

Toggle sidebar
bg1
"""
This program takes five full names from the user,
extracts the last names, sorts them alphabetically,
and prints the sorted list of last names.
"""
# Create an empty list to store last names
last_names = []
# This loop collects five full names from the user, extracts
# their last names, and adds them to the last_names list.
for i in range(5):
full_name = input("Name: ")
last_name = full_name.split()[-1]
last_names.append(last_name)
# Sort the list of last names in alphabetical order
last_names.sort()
# Print the sorted list of last names
print(last_names)

Partial preview of the text

Download Coding python computer science and more Schemes and Mind Maps Computer science in PDF only on Docsity!

This program takes five full names from the user, extracts the last names, sorts them alphabetically, and prints the sorted list of last names. """

Create an empty list to store last names

last_names = []

This loop collects five full names from the user, extracts

their last names, and adds them to the last_names list.

for i in range(5): full_name = input("Name: ") last_name = full_name.split()[-1] last_names.append(last_name)

Sort the list of last names in alphabetical order

last_names.sort()

Print the sorted list of last names

print(last_names)