2014-11-17 59 views
0

我遇到了我的while循環問題。出於某種原因,當不等於Q或q時,不會繼續詢問變量「lotNumber」。儘管變量不等於Q

def main(): 
    lotNumber="" 

    output="" 

    todayMonth=getValidMonth("the month for Today's Date: ") 

    todayDay=getValidDay("the day for Today's Date: ",todayMonth) 

    todayYear=getValidYear("the year for Today's Date: ")  

    todayDate=calculateJulianDate(todayMonth, todayDay) 

    lotNumber=input("Please enter the next lot number or Q to exit: ") 
    if lotNumber=="Q": 
     print("================ Egg Grading Report ================") 
     print("\t"+"\t"+"\t"+str(todayMonth)+"/"+str(todayDay)+"/"+str(todayYear)+"\t"+"\t"+"\t") 
     print(output) 
    while lotNumber!="Q" or lotNumber!="q": 

     lotMonth=getValidLotMonth("the month for the date lot " +lotNumber+ " was laid: ") 

     lotDay=getValidLotDay("the the day for the date lot " +str(lotNumber) +" was laid: ",lotMonth) 

     lotYear=getValidLotYear("the the year for the date lot " +str(lotNumber)+ " was laid: ") 

     lotDate=calculateJulianLotDate(lotMonth, lotDay) 

     daysOld=todayDate-lotDate 

     age=daysOld 

     grade=calculateGradeOfEgg(daysOld) 

     age=daysOld 

     output= output=output +str(lotNumber) +"\t" +lotDate +"\t" +age +"\t" +grade+"\n" 

     lotNumber=gettingLotNumber(lotNumber, lotMonth, lotDay, lotYear, output) 

    print("================ Egg Grading Report ================") 

    print("\t"+"\t"+"\t"+str(todayMonth)+"/"+str(todayDay)+"/"+str(todayYear)+"\t"+"\t"+"\t") 

    print(output) 


main() 

當然,這裏有不同的功能。我無法得到這個織物,而循環爲我工作!幫助幫助幫助!

謝謝!

+0

您可以分享getsLotNumber()代碼,因爲它在循環結束之前重新分配lotNumber嗎? – kartikg3

回答

-1

您需要的getinput行添加到while循環的最後一行:

lotNumber=input("Please enter the next lot number or Q to exit: ") 
0

while循環是無限的,你想要的and運營商不or,和更好的條件是while lotNumber not in ('Q', 'q'):

1

你是不是問批號爲環路(在while循環套件)

q = 'foo' 
while q != 'q' and q != 'Q': 
    print(q) 
    q = raw_input('q? ') 
    #q = input('q? ') for Python 3x 

>>> 
foo 
q? bar 
bar 
q? baz 
baz 
q? q 
>>>