如題,本人寫了一個求1-100的奇數代碼,出現如下報錯,求大神支招n=1while n<101: num = n % 2 if num==0 : pass else: print (n) n=n+1print ('end') KeyboardInterrupt Traceback (most recent call last)<ipython-input-35-d0485a6ca3d8> in <module>() 1 n=1 2while n<101:----> 3 num = n %2 4 if num==0: 5 passKeyboardInterrupt:
1 回答

白衣染霜花
TA貢獻1796條經驗 獲得超10個贊
count = 0while (count < 101): if count%2 != 0: print 'The count is:', count count = count + 1print "Good bye!"
沒用過python 你的安裝環境或者包什么的有沒有問題我不知道,但是我能肯定你的循環寫的有問題,n=n+1在else里面,那么應該跳不出循環,上面是我看教程寫的能在線運行的代碼。
添加回答
舉報
0/150
提交
取消