17 Dec PMCA Saturday 18:30 Python Homework 20.12.12.
Question:
Write a Python program to create a list by concatenating (joining) a given list [‘p’, ‘q’] which range goes from 1 to n.
Sample Input: n: 5 Sample Output: ['p1', 'q1', 'p2', 'q2', 'p3', 'q3', 'p4', 'q4', 'p5', 'q5']
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'
Sorry, the comment form is closed at this time.