Skip to content
Exercises · Q7

Q.Write a program to repeat the string "GOOD MORNING" n times. Here n is an integer entered by the user.

Sikkim CbseNCERTSubjective· 3mImportance★★★★★est
80% · 20/25 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

This program uses Python's string repetition operator (*) to repeat "GOOD MORNING" as many times as the user specifies — a clean, one-line solution that avoids loops entirely.

Why String Repetition?

When you need to repeat a string a fixed number of times, Python gives you a direct tool: the * operator on strings. This isn't multiplication in the arithmetic sense — it's string repetition, a built-in feature that creates a new string by concatenating the original with itself n times.

The beauty of this approach is that it handles the entire operation in a single expression, with no loop, no manual concatenation, and no risk of off-by-one errors. The interpreter does the heavy lifting internally, making the code both faster and more readable.

# Program to repeat "GOOD MORNING" n times

# Take integer input from the user
n = int(input("Enter the number of times to repeat: "))

# Repeat the string using the * operator
result = "GOOD MORNING" * n

# Display the result
print(result)

Expected output (for n = 3):

GOOD MORNINGGOOD MORNINGGOOD MORNING
Watch out

Notice that the repeated string has no spaces between repetitions — the * operator simply concatenates the exact string. If you want spaces between each "GOOD MORNING", you'd need to add a space at the end of the original string: "GOOD MORNING " * n, or join them differently.

Key Line Explained

The core of the program is this single line:

result = "GOOD MORNING" * n

Here's what happens step by step:

  • Python evaluates n (an integer, say 3) …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.