Question 16 of 22beginner🔧 ApplyLong Answer4 marks

Write a program to repeat the string “GOOD MORNING” n times. Here ‘n’ is an integer entered by the user.

Correct Answer

Program to repeat the string "GOOD MORNING" n times

Objective: To accept an integer n from user and display the string repeated n times

Accepting integer input from user

n = int(input("Enter the number of times to repeat: "))

Repeating the string using multiplication operator

result = "GOOD MORNING " * n

Displaying the output

print(result)

Example Output:

Enter the number of times to repeat: 3

GOOD MORNING GOOD MORNING GOOD MORNING

Exercise: EXERCISE | Q: 16 | (Page 32)
For More Understanding

Explanation

This question tests the student's understanding of string operations in Python, specifically string multiplication. The program uses the string multiplication operator (*) which repeats the string n times. The input() function accepts user input as a string, which is then converted to an integer using int(). The expression "GOOD MORNING " * n creates a new string with the original string repeated n times. This is a fundamental string operation covered in NCERT Class 11 Computer Science under string handling concepts.

Solution Steps

  1. Step 1: Accept integer input from user using int(input())

  2. Step 2: Use string multiplication operator (*) to repeat the string n times

  3. Step 3: Store the result in a variable

  4. Step 4: Display the output using print() function