Slip 22 - A) Write a python class to accept a string and number n from user and display n repetition of strings by overloading * operator.

Solution :

Post a Comment

1 Comments

  1. class Rep:
    def __init__(self, s):
    self.s = s
    def __mul__(self, n):
    return self.s * n

    # Input and usage
    string = input("Enter string: ")
    n = int(input("Enter number: "))
    obj = Rep(string)
    print(obj * n)

    ReplyDelete