Answer to the python question asked for finding the index of an element in a list
class FindingElement:
def __init__(self):
self.list1 = ["demo","nemo", "memo"]
def find_element(self, ele):
try:
return "Found {} at index {}".format(ele, self.list1.index(ele))
except ValueError:
return "{} not found".format(ele)
obj = FindingElement()
isTrue = True
while isTrue:
findvar = input("What do you want to search? ")
print("Type of input: {}".format(type(findvar)))
print("Is it a string? {}".format(isinstance(findvar, str)))
print(obj.find_element(findvar))
try:
isTrue = bool(int(input("Continue? 1 for yes, 0 for no: ")))
except ValueError:
print("Incorrect Input. Continuing with the program.")
Comments
Post a Comment