In the code below, when we run m.choose_slot()
, and enter the slot by entering the number, it gets popped from the entered location instead of the number from the list itself ,even though in the for loop I mentioned i==b
(iterator is equal to the entered number that is b
). I want the number entered to be popped.P.S I am a beginner in Python and I am doing this as a part of my first project.
class Doctor():
a=[0,1,2,3,4,5,6,7,8]
def __init__(self,hours):
self.hours=hours
print("The doctor is Free for {} hours a day".format(self.hours))
def scheduler(self):
print("The available slots are:")
for i in self.a:
print(i)
d=Doctor(8)
d.scheduler()
class Patient(Doctor):
def __init__(self):
d.scheduler()
def choose_slot(self):
while True:
try:
b=int(input("Choose a slot from the given table: "))
if b in range(1,8):
for i in self.a:
if i==b:
self.a.pop(b)
print("The slot is scheduled at {}".format(b))
return d.scheduler()
break
else:
return "The entered slot is not available!"
continue
except:
print("Please check your entry again")
m=Patient()
m.choose_slot()