Practice: Print Function

« Read the chapter

Q1. Print three words

BeginnerCoding

Print the words red, green and blue on one line separated by commas and a space, using sep.

Goal: Use sep.

Q2. Stay on one line

BeginnerCoding

Print the numbers 1 to 5 on one line separated by spaces using a loop and end.

Goal: Use end.

Q3. Date format

BeginnerCoding

Print the day 15, month 03 and year 2025 as 15/03/2025 using sep.

Goal: Use sep with mixed types.

Q4. Two lines in one call

BeginnerCoding

Print Hello and World on two lines using a single print call with a newline escape.

Goal: Use \n.

Q5. Tab table

IntermediateCoding

Print a header Name and Score separated by a tab, then Asha and 90 separated by a tab.

Goal: Use \t.

Q6. Box line

BeginnerCoding

Print a line of 12 stars, then the text Done, then another line of 12 stars.

Goal: Repeat strings.

Q7. Unpack a list

IntermediateCoding

Print the items of [4, 8, 15] on one line with ' | ' between them without using a loop.

Goal: Use * unpacking.

Q8. Debug display

AdvancedCoding

Given a = 3 and b = 4, print both names and values in the form a=3 then b=4 using f-string equals.

Goal: Use {x=}.

Q9. Default separator

BeginnerOutput

What does this print?

Code
print("a", "b", "c")

Goal: Know default sep.

Q10. End argument

BeginnerOutput

What does this print?

Code
print("A", end="-")
print("B", end="-")
print("C")

Goal: Predict end.

Q11. Return value

IntermediateOutput

What does this print?

Code
r = print("hi")
print(r)

Goal: Know print returns None.

Q12. Escape lengths

IntermediateOutput

What does this print?

Code
s = "a\tb\n"
print(len(s))

Goal: Count escape characters.

Q13. Raw string

IntermediateOutput

What does this print?

Code
print(r"x\ny")
print("x\ny")

Goal: Compare raw and normal strings.

Q14. Sep with newline

IntermediateOutput

What does this print?

Code
print(1, 2, 3, sep="\n")

Goal: Use newline as sep.

Q15. Quotes in lists

AdvancedOutput

What does this print?

Code
print("hi")
print(["hi"])
print(("hi", 1))

Goal: Know str versus repr display.

Q16. Fix the Python 2 print

BeginnerDebugging

This old-style line fails in Python 3. Fix it so it prints Welcome.

Code
print "Welcome"

Goal: Fix print syntax.

Q17. Fix the separator

BeginnerDebugging

The date should print as 2025-01-05 but prints with extra spaces. Fix it.

Code
print(2025, "-", "01", "-", "05")

Goal: Fix a separator mistake.

Q18. Fix the path

IntermediateDebugging

The path should print as C:\temp\new but the escapes spoil it. Fix it.

Code
print("C:\temp\new")

Goal: Use raw strings.

Q19. Why None

IntermediateConceptual

Why does text = print("hello") leave text equal to None?

Goal: Explain print's return value.

Q20. stdout versus stderr

AdvancedConceptual

Why might a program print error messages with file=sys.stderr instead of the normal print?

Goal: Explain streams.