In: Computer Science
Write a program called listful.py, in which the user inputs names, which get added to a list. Your program should:
· Include a comment in the first line with your name.
· Include comments describing each major section of code.
· Create a list.
· Ask the user to input a first name or hit enter to end the list.
· If the user adds a first name (i.e., anything other than a blank value):
o Add the name to the list.
o Tell the user that they’ve added [name] to the list (where [name] is the name that just got added).
o Ask the user (again) to input a first name — and keep asking until the user hits enter without adding another name (i.e., enters a blank value).
· Once the user enters a blank value:
o Tell the user how many names they added to the list.
o Using a for-loop, output all the names that are in the list, using a separate line for each name.
o Do not include the blank value in the list!
Code:
# Add your name here
# create a list
names = []
# we use while loop to keep accepting input names
while(1):
name = input('Enter first name or hit enter to end the list: ')
if(name == ''): # user has hit enter so end the list
break
names.append(name)
print(name,'got added to list')
# tell user number of names they have added to list
print('Total names added =',len(names))
# use for loop to output names
for i in range(len(names)):
print(names[i])
Code Screenshot:
Code output:
==============
Please add your author name in the code first line.
Please refer to the code and screenshot attached above.
Please upvote.