← All coding practice

Coding Practice · Beginner · October 3, 2026 · 3 min read

Python Coding Exercise #03: Printing Output

Part of the series Python Practice Exercise — part 3

Before you start: Know what print() does · Know basic arithmetic operators in Python

This post groups two exercises that are both about print(): one prints the result of a calculation, and the other prints text that contains quotation marks.

Exercise 1: Minutes in a year

The question

Please write a program which prints out the number of minutes in a year. Use Python code to perform the calculation, as in the previous code example.

My Solution

print("Minutes in a year:")
print(365*24*60)

Output:

Minutes in a year:
525600

How it works

The first line prints a text label. Because it is wrapped in quotation marks, Python treats it as a string and prints it exactly as written.

The second line has no quotation marks around 365*24*60, so Python does not print it as text. Instead, it calculates it first and prints the result. Inside print(), * means multiplication:

  • 365 days in a year
  • × 24 hours in a day
  • × 60 minutes in an hour
  • = 525,600 minutes

Compare the two versions below. The quotation marks make all the difference:

print("365*24*60")   # prints the text:   365*24*60
print(365*24*60)     # prints the result: 525600

You can also check the pieces separately. One day has 24*60 = 1440 minutes, and a year of 365 days has 1440 * 365 = 525600 minutes.

A small extra: a leap year has 366 days, so it has 366*24*60 = 527040 minutes. The exercise asks for a normal 365-day year, which is why the answer is 525,600. (Leap years are the subject of Exercise #40 and Exercise #48.)

Exercise 2: Printing a line of code

The question

Please write a program which prints out the following:

print("Hello there!")

The program has to print the text print("Hello there!"), including the quotation marks and the brackets, rather than run it.

My Solution

print('print("Hello there!")')

Output:

print("Hello there!")

How it works

Normally, a string starts and ends with the same type of quotation mark. If you wrote print("print("Hello there!")"), Python would think the string ends at the second ", and you would get a syntax error.

The trick is to use single quotes on the outside and double quotes on the inside. Python lets you use either kind of quote to start a string, and the other kind is then just an ordinary character inside it. So the double quotes around Hello there! are printed as part of the text.

There are other ways to get the same output:

print("print(\"Hello there!\")")    # \" is an "escaped" double quote
print('''print("Hello there!")''')  # triple quotes also work

The backslash in \" tells Python “treat the next character as a plain character, not as the end of the string”. Mixing single and double quotes is usually the neatest option.

Key takeaways

  • Text in quotation marks is a string and is printed exactly as written.
  • An expression without quotation marks, like 365*24*60, is calculated first, and print() shows the result.
  • To print quotation marks, wrap the string in the other kind of quote, or escape them with a backslash.
  • Spaces inside a string are real characters. They get printed too.

✦ This is part of my Python Practice Exercise series, where I work through exercises while learning Python and explain each answer in plain language. ✦


Practice Source: These exercises are taken from the Python Programming MOOC 2026 by the University of Helsinki. I’m working through the exercises as part of my Python learning journey and documenting my answers and explanations here.

Tagged: python · print · strings · arithmetic · quotes