26 Aug Wednesday Friday 15:00 Python Practice 20.08.26.
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 at the end. It should look something like this:
Sample input: Enter 5 names: Tony Paul Nick Michel Kevin Sample output: The names are Tony, Paul, Nick, Michel, Kevin
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'
Jesse Shi
Posted at 03:53h, 28 Augustname = int(input(‘Gimme five names: ‘))
I forgot how to line up things…
else I am going to write it here.
namelist = [‘1’, ‘2’, ‘3’, ‘4’, ‘5’]
name = input()
nameslist.append(name)
str_name = ‘, ‘.join(nameslist)
print(str_name)
What I was trying to do is to make namelist = [‘1’, ‘2’, ‘3’, ‘4’, ‘5’] line up it’s 12345.
And then make the program print out the five names.
because they are the 5 names that the user type in.
Ethan Li
Posted at 19:03h, 28 Augustnames=input(‘Please input 5 names!’)
print(‘The names are: ‘)
print(‘, ‘.join(names))