变量不等于Q.

时间:2014-11-17 02:51:20

标签: python

我的while循环问题。由于某种原因,当不等于Q或q时,它不会继续要求变量“lotNumber”。

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

当然,这里有不同的功能。循环为我工作时,我无法得到这个蠢!帮助帮助!

谢谢!

3 个答案:

答案 0 :(得分:2)

您不是要求循环中的批号(在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
>>> 

更好的

while q not in ('q','Q'):
    ....

答案 1 :(得分:0)

你的while循环是无限的,你希望and运算符不是or,更好的条件是while lotNumber not in ('Q', 'q'):

答案 2 :(得分:-1)

您需要将getinput行添加到while循环的最后一行:

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