2014-04-18 62 views
0

考慮下面的代碼,當我運行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!' 
+0

你正在使用哪個版本的python? –

+0

@WinstonEwert從'print'判斷,2.x – aIKid

+0

@alKid,doh!我應該看到這一點。 –

回答

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 - 它評估你的輸入,可能會危害您的代碼。

+0

問題沒有出現在@alKid –

+0

這就是爲什麼我問..發生了什麼? – aIKid

+0

相同的輸出,它不斷重複第一行代碼 –