I am new to python, please help me with the below question-
Question: You have already given a class base
, now you have to declare a class called code
which inherits the class base
and calls the hello
of the base
class.
Example:
- Input:
4
- Output:
["Hello Python", "Hello Python", "Hello Python", "Hello Python"]
class base:
def __init__(self,n):
self.n=n
def hello(n):
return ["Hello Python" for i in range(n)]
I tried as below:
class code(base):
def __init__(self):
base.__init__(self,5)
x=code()
x.hello()
but got error:
TypeError Traceback (most recent call last)
<ipython-input-88-1a7429b02c84> in <module>
12 base.__init__(self,5)
13 x=code()
---> 14 x.hello()
<ipython-input-88-1a7429b02c84> in hello(n)
3 self.n=n
4 def hello(n):
----> 5 return ["Hello Python" for i in range(n)]
6
7
TypeError: 'code' object cannot be interpreted as an integer