How to Repeat a String in Python

In this tutorial we are going to show you How to Repeat a String in Python.

So, we are going to write a program that captures text from the user in python. Then print the user string as many times as its length. Print as many lines of this as the length of the user input. Important, do not put a prompt when asking for user input. Just use input(). Adding a prompt will cause your program to not pass the tests.

Expected Output

• If the user types cat then the program will print: 

Implementation of How to Repeat a String in Python

#Solution by

#Get the user input and store it in the variable string
string = input()

#Using len() function get the length of the string
length = len(string) 

#Using for loop to repeat number of times equal to length
for x in range(length):
     for x in range(length):
         print(string, end ="")

#save the file as

Download Sourcecode Here

The above code will produce the output as below

How to Repeat a String in Python
Output of How to Repeat a String in Python

Instructions on how to run the source code

You can use online python interpreter if you haven’t configured python on your computer.

To execute the above code, Open CMD and make sure you are in the directory where your file is. Then run the below code



Please enter your comment!
Please enter your name here