Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Print List ItemsE02. Sum List NumbersE03. Count List ElementsE

Problem No 1

Print List Items

Easy

6 minute session

Summary

Practice iterating over a list and producing a formatted multi-line string.

Problem statement

Create a function print_items(items) that takes a list of values and returns a single string with each item's string representation on its own line (separated by '\n'). Do not print to stdout — return the constructed string. For an empty list, return an empty string. Convert non-string items to their string form before joining.

Task

Write a function that iterates through a list and returns a single string where each item appears on its own line.

Examples

Basic example

Input

print_items([1, 2, 3])

Output

1 2 3

Explanation

Each list item becomes a line in the returned string.

Input format

A single list named items passed as the function argument.

Output format

A single string with list items separated by newlines. Empty string for empty list.

Constraints

- items length may be 0 or more. - Items may be of any type; convert each to str before joining. - Use a loop to build the result (avoid using join directly on pre-built strings in starter code requirement).

Samples

Sample input 0

print_items(['a', 'b', 'c'])

Sample output 0

a b c

Explanation 0

Each element from the list is on its own line.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

02:05 PM

Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.