class alphabet():
def all():
start=str(input('enter the alphabet you want to start with'))
end=str(input('enter the alphabet you want to end with'))``
for j in range (0,25):
if start==chr(65 j):
start=65 j
for k in range(1,25):
if end==chr(65 k):
end=65 k
for i in range (start,end):
print(chr(i))
alphabet(all())
please solve the error as quick as possible i am trying to make a class "alphabets " in which i am def a function named 'all' which will write alphabets starting and ending on users input
CodePudding user response:
Dont use all
. It is a builtin reserved function is python. Rename it.
See here.
CodePudding user response:
There are a couple of problems with this code.
alphabet(all())
does not do what you are expecting. Calling the classalphabet()
creates an object instance of the class. In this case you are creating an instance and passing theall()
as an argument.all
is a built-in python function that expects at least one argument. That is the source of your error. You should always avoid defining functions with the name of python built-in functions.
I would suggest to just create a function performing the task you need to do. If you need it to be a class method, this is the format you should be using:
class MyClass:
'''A minimal class example.'''
def my_method(self):
'''A minimal method example'''
# my code here
Then you call the method by doing:
my_class_instance = MyClass()
my_class_instance.my_method() # calls the method