How to Output Repeated Characters in Python


In this example we will show how to output a character repeatedly for N times using Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

num = int(input('input a number between 1 and 50:n'))
while num < 1 or num > 50:
    num = int(input('input a number:n'))

print('nThe character # is printed out for %s times:'%num)
print(num * '#')

Output:

Please input a number between 1 and 50:
 20

The character # is printed out for 20 times:
#############
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments