Editor

Print Items on the Same Line

Beginner · Write the code · from Python Input and Output: print(), input(), and Formatting

From the lesson: Python Input and Output: print(), input(), and Formatting

Every program needs a way to talk to the outside world. A weather app shows temperatures. A game displays your score. A calculator prints answers. All of these use output.

Read the lesson

Use a for loop to print the numbers 1 through 5 on the same line, separated by spaces. Add an empty print() at the end to finish the line.

Expected output:

1 2 3 4 5

Use the end parameter inside the loop. Be careful not to add a trailing space after 5.

# Print numbers 1 through 5 on the same line
for i in range(1, 6):
# Use end parameter to stay on the same line
pass # Replace this line
print() # Final newline

More Input and Output exercises

All Python exercises · 50 practice problems · Python Fundamentals quiz