हिंदी

Write a program to repeat the string ‘‘GOOD MORNING” n times. Here ‘n’ is an integer entered by the user. - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

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

संक्षेप में उत्तर
Advertisements

उत्तर

The string will be repeated only if the value is greater than zero, otherwise, it will return a blank. Therefore, the ‘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
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 5: Getting Started with Python - Exercise [पृष्ठ ११८]

APPEARS IN

एनसीईआरटी Computer Science [English] Class 11
अध्याय 5 Getting Started with Python
Exercise | Q 16. | पृष्ठ ११८
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×