В приведенном ниже коде, когда мы запускаем m.choose_slot()
и вводим слот, вводя номер, он выталкивается из введенного местоположения вместо номера из самого списка, хотя в цикле for, который я упомянул i==b
(итератор равен введенному номеру b
). Я хочу, чтобы введенный номер был перенесен. P. Я новичок в Python, и я делаю это как часть моего первого проекта.
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()