목록에 3 명이 대기열에 추가되어 각 사람의 이름이 맨 위에 표시되지만 이름없이 결과 하나만 얻을 수있었습니다 :대기열 데이터 구조 목록 (Python)에서 항목 호출하기
Contacting the following
Phone answered: Yes
Booked an appointment: No
Reshedule an appointment again.
내가 그들의 이름과 3 개 출력, 'names'
내부에 저장된 정보에서 각 사람 하나를 표시하는 출력을 만들고 싶어하고, 각각의 이름이 두 번 나타나지 않습니다.
대기열을 사용하여 목록에 따라 우선 순위를 정하고 싶습니다. 그래서 순서대로 나열하려고합니다. if와 elif는 임의의 생성자에 따라 두 범주 중 하나에 속하는 조건입니다. 이제는 내부에 이름을 포함시키는 방법이 정의되지 않은 것입니다.
코드
import random
class Queue:
def __init__(self):
self.container = []
def isEmpty(self):
return self.size() == 0
def enqueue(self, item):
self.container.append(item)
def dequeue(self):
self.container.pop(0)
def size(self):
return len(self.container)
def peek(self) :
return self.container[0]
names = ["Alvin", "James", "Peter"]
# Enqueuing
q = Queue()
q.enqueue(random.choice(names))
# Dequeuing and Printing
print("Contacting the following:\n" + "\n".join(q.container)) # unsure about this
for i in range(q.size()):
answered = random.randint(0,1)
booked = random.randint(0, 1)
if(answered == 1 and booked == 1):
print("Now Calling -" + (q.names)) # unsure about this
print("Phone answered: Yes")
print("Booked an appointment: Yes")
print("Booking successful.")
elif(answered==1 and booked==0):
print("Now Calling -" + (q.names)) # unsure about this
print("Phone answered: Yes")
print("Booked an appointment: No")
print("Reshedule an appointment again.")
elif(answered == 0):
print("Now Calling -" + (q.names)) # unsure about this
print("Phone answered: No")
print("Reshedule a callback.")
q.dequeue()
예 원하는 출력 :
Contacting the following
Alvin
James
Peter
Now Calling - James
Phone answered: No
Reshedule a callback.
했다 https://stackoverflow.com/questions/47736687/showing-names-in-the-queue-data-structure # 47736687) 삭제했을 때 ... –
죄송합니다. 나는 내 자신을 알아 내려고 노력할 것이라고 생각했다. 출력에 – John