用这段代码调查错误?

时间:2014-04-18 04:34:24

标签: python debugging runtime

考虑下面的代码,当我在执行while循环后只运行它时,if语句似乎不存在我无法确切地知道错误的位置。

while True:

    IN = input("   ====================================== \n    CPU scheduler console application: \n   ====================================== \n   1.FCFS \n   2.SJF \n   3.Periority algorithm \n   4.Round robin \n   5.Exit \n   Enter the chosen algorithm to run: ")

if IN == 1:
    Processes = input("   Enter the  processes times & arrival times separated by a comma: ")
    BurstTimes = Processes[::2]
    ArrivalTimes = Processes[1::2]
    print BurstTimes, '\t\t', ArrivalTimes,
else:
    print 'Good Bye!'

1 个答案:

答案 0 :(得分:2)

缩进if子句:

while True:

    IN = raw_input("   ====================================== \n    CPU scheduler console application: \n   ====================================== \n   1.FCFS \n   2.SJF \n   3.Periority algorithm \n   4.Round robin \n   5.Exit \n   Enter the chosen algorithm to run: ")

    if IN == '1': #change this to a string

        Processes = input("   Enter the  processes times & arrival times separated by a comma: ")
        BurstTimes = Processes[::2]
        ArrivalTimes = Processes[1::2]
        print BurstTimes, '\t\t', ArrivalTimes,
    else:
        print 'Good Bye!'

使用raw_input和字符串代替input更好的做法 - 评估您的输入并可能对您的代码有害。