TORONTO KIDS COMPUTER CLUB | Wednesday 17:00 Python Practice – 22.05.04.
20617
post-template-default,single,single-post,postid-20617,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Wednesday 17:00 Python Practice – 22.05.04.

08 May Wednesday 17:00 Python Practice – 22.05.04.

Question:

Write a program to ask the user for five names. The program should store the names in a list, and print them all out in alphabetical order at the end. It should look something like this:


Sample input:

Enter 5 names:
Tony
Paul
Nick
Michel
Kevin

Sample output:

The names are Kevin, Michel, Nick, Paul, Tony

Hint:
You can use for loop repeat 5 times to ask names
You could use list.append() to add name into the list, for example:
>>> nameslist = []
>>> name = input()
>>> nameslist.append(name)
For better display result, you can use separator.join(list) to convert a list into one string, each item will be separated by the separator, for example:
>>> nameslist = ['Sam','Kevin','Joe']
>>> str_name = ', '.join(nameslist)
>>> print(str_name)
>>> 'Sam, Kevin, Joe'
No Comments

Sorry, the comment form is closed at this time.