CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
255
You visited us 255 times! Enjoying our articles? Unlock Full Access!
Question

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

Open in App
Solution

The string will be repeated only if the value is greater than zero, otherwise, it will return a blank. Therefore, ‘if’ condition will be used to check the values of 'n' first and then the print statement will be executed.

Program:
str = "GOOD MORNING "
n = int(input("Enter the value of n: "))

if n>0:
print(str * n)
else:
print("Invalid value for n, enter only positive values")


OUTPUT:
Enter the value of n: 5
GOOD MORNING GOOD MORNING GOOD MORNING GOOD MORNING GOOD MORNING

flag
Suggest Corrections
thumbs-up
26
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Properties of Addition and Subtraction of Integers
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon