第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 def 函數(shù)之后運(yùn)行 for 循環(huán)?

如何在 def 函數(shù)之后運(yùn)行 for 循環(huán)?

蕭十郎 2023-03-16 10:04:01
我試圖在 def 函數(shù)之后運(yùn)行最后一個(gè) for 循環(huán),但它并沒(méi)有像我想的那樣運(yùn)行。lst = [] print(lst)print('The queue is now empty...')MaxQueue = int(input('\nSet The Maximum Queue to: '))for i in range(0, MaxQueue):     print(lst)    inn = input('Enter Name: ')    lst.append(inn)  print('')   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? '))for i in range(MaxQueue,0):    print(lst)    de = input('press (enter) to serve')    print(lst.pop(0))
查看完整描述

2 回答

?
慕田峪9158850

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))


查看完整回答
反對(duì) 回復(fù) 2023-03-16
?
神不在的星期二

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))


查看完整回答
反對(duì) 回復(fù) 2023-03-16
  • 2 回答
  • 0 關(guān)注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)