Write a program using python that prints a given number for a given number of times.
For example:
Enter a number : 4
4444
Answers
Answered by
28
Printing a number of times - Python
We would take a user input string first, to enter a number.
We know that the input() function returns a string, string is one of the basis types in Python that store text.
To convert it to a number, we can use the function.
After that we use str class. creates a string format of a value. We know that the class converts the argument provided to string datatype.
We then print the number, after that we will display the required result of the program.
The Program
num=int(input('Enter a number:'))
x=str(num)
print(num*x)
Sample run
Case 1:
Enter a number: 5
55555
Case 2:
Enter a number: 8
88888888
Answered by
7
Required Answer:-
n=int(input("Enter a number:"))
print((str(n))*n)
Logic:-
- Simply convert to string data type and multiply with same number
- it will print multiple times.
Required Output Attached.
Attachments:
Similar questions