2 回答

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超7個(gè)贊
你的大問(wèn)題是range函數(shù)寫(xiě)錯(cuò)了,你在較低的值之前輸入了較高的值,這是錯(cuò)誤的。與這個(gè)問(wèn)題相比,您的其他問(wèn)題可能是次要的,但仍然非常重要!確保始終檢查您的輸入以避免意外行為,例如負(fù)數(shù)或零。修復(fù)方法是:
lst = []
print(lst)
print('The queue is now empty...')
MaxQueue = int(input('\nSet The Maximum Queue to: '))
# A loop to ensure the user will never be able to insert a value lower than 1.
while MaxQueue <= 0:
print('Cannot receive a length lower than 1!')
MaxQueue = int(input('\nSet The Maximum Queue to: '))
for i in range(0, MaxQueue):
print(lst)
inn = input('Enter Name: ')
lst.append(inn)
print('\n')
print(lst)
print('The Queue is full..')
def get_answer(prompt):
while True:
answer = input(prompt)
if answer not in ('yes','no'):
answer = input(prompt)
if answer in ('yes'):
break
if answer in ('no'):
exit()
print(get_answer('Do you want to start seriving? (yes/no):'))
for i in range(0, MaxQueue):
print(lst)
input('press (enter) to serve') # no need to save input.
print(lst.pop(0))

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊
起點(diǎn)超過(guò)終點(diǎn)的范圍是空的。您get_answer還包含一些錯(cuò)誤。
lst = []
print(lst)
print('The queue is now empty...')
MaxQueue = int(input('\nSet The Maximum Queue to: '))
for i in range(MaxQueue):
print(lst)
inn = input('Enter Name: ')
lst.append(inn)
print('')
print(lst)
print('The Queue is full..')
def get_answer(prompt):
answer = None # set initial value to make sure the loop runs at least once
while answer not in ('yes', 'no'):
answer = input(prompt)
if answer == 'no':
exit()
get_answer('Do you want to start serving? ')
for i in range(MaxQueue):
print(lst)
input('press (enter) to serve')
print(lst.pop(0))
對(duì)于較大的程序,放在中間通常不是一個(gè)好主意exit(),因?yàn)槟赡芟胱銎渌虑?,所以我們可以改用布爾邏輯并做類似的事?/p>
def get_answer(prompt):
answer = None # set initial value to make sure the loop runs at least once
while answer not in ('yes', 'no'):
answer = input(prompt)
return answer == 'yes'
if get_answer('Do you want to start serving? '):
for i in range(MaxQueue):
print(lst)
input('press (enter) to serve')
print(lst.pop(0))
添加回答
舉報(bào)