调查此代码的错误?

2024-04-25 05:09:10 发布

您现在位置:Python中文网/ 问答频道 /正文

当我只在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!'

Tags: the代码ininputif错误语句algorithm
1条回答
网友
1楼 · 发布于 2024-04-25 05:09:10

缩进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,这会评估您的输入,可能对您的代码有害

相关问题 更多 >