Python 練習(xí)實例38 Python 100例 題目:求一個3*3矩陣對角線元素之和。 程序分析:利用雙重for循環(huán)控制輸入二維數(shù)組,再將a[i][i]累加后輸出。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': a = [] sum = 0.0 for...
http://m.o2fo.com/python/python-exercise-example38.htmlPython 練習(xí)實例48 Python 100例 題目:數(shù)字比較。 程序分析:無 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': i = 10 j = 20 if i > j: print '%d 大于 %d' % (i,j) elif i == j: print '%d 等于 %d' % (i,j) elif i &l...
http://m.o2fo.com/python/python-exercise-example48.htmlPython 練習(xí)實例58 Python 100例 題目:畫圖,學(xué)用rectangle畫方形?! ?程序分析: rectangle(int left, int top, int right, int bottom) 參數(shù)說明:(left ,top )為矩形的左上坐標,(right,bottom)為矩形的右下坐標,兩者可確定一個矩形的大小 程序...
http://m.o2fo.com/python/python-exercise-example58.htmlPython 練習(xí)實例39 Python 100例 題目:有一個已經(jīng)排好序的數(shù)組?,F(xiàn)輸入一個數(shù),要求按原來的規(guī)律將它插入數(shù)組中。 程序分析:首先判斷此數(shù)是否大于最后一個數(shù),然后再考慮插入中間的數(shù)的情況,插入后此元素之后的數(shù),依次...
http://m.o2fo.com/python/python-exercise-example39.htmlPython 練習(xí)實例49 Python 100例 題目:使用lambda來創(chuàng)建匿名函數(shù)。 程序分析:無 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- MAXIMUM = lambda x,y : (x > y) * x + (x < y) * y MINIMUM = lambda x,y : (x > y) * y + (x < y) * x if __name__ == '__mai...
http://m.o2fo.com/python/python-exercise-example49.htmlPython 練習(xí)實例40 Python 100例 題目:將一個數(shù)組逆序輸出。 程序分析:用第一個與最后一個交換。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': a = [9,6,5,4,1] N = len(a) print a for i in range(len(a) / 2): a[i],a[N - ...
http://m.o2fo.com/python/python-exercise-example40.htmlPython 練習(xí)實例50 Python 100例 題目:輸出一個隨機數(shù)。 程序分析:使用 random 模塊。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- import random #生成 10 到 20 之間的隨機數(shù) print random.uniform(10, 20) 以上實例輸出結(jié)果為: 14.4012371357 Py...
http://m.o2fo.com/python/python-exercise-example50.htmlPython 練習(xí)實例60 Python 100例 題目:計算字符串長度?! ?程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- sStr1 = 'strlen' print len(sStr1) 以上實例輸出結(jié)果為: 6 Python 100例
http://m.o2fo.com/python/python-exercise-example60.htmlPython 練習(xí)實例41 Python 100例 題目:模仿靜態(tài)變量的用法。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- def varfunc(): var = 0 print 'var = %d' % var var += 1 if __name__ == '__main__': for i in range(3): varfunc() # 類的屬...
http://m.o2fo.com/python/python-exercise-example41.htmlPython 練習(xí)實例51 Python 100例 題目:學(xué)習(xí)使用按位與 & 。 程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': a = 077 b = a & 3 print 'a & b = %d' % b b &= 7 print 'a & b = %d' % ...
http://m.o2fo.com/python/python-exercise-example51.html抱歉,暫時沒有相關(guān)的微課
w3cschool 建議您:
抱歉,暫時沒有相關(guān)的視頻課程
w3cschool 建議您:
抱歉,暫時沒有相關(guān)的教程
w3cschool 建議您:
Python 練習(xí)實例38 Python 100例 題目:求一個3*3矩陣對角線元素之和。 程序分析:利用雙重for循環(huán)控制輸入二維數(shù)組,再將a[i][i]累加后輸出。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': a = [] sum = 0.0 for...
http://m.o2fo.com/python/python-exercise-example38.htmlPython 練習(xí)實例48 Python 100例 題目:數(shù)字比較。 程序分析:無 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': i = 10 j = 20 if i > j: print '%d 大于 %d' % (i,j) elif i == j: print '%d 等于 %d' % (i,j) elif i &l...
http://m.o2fo.com/python/python-exercise-example48.htmlPython 練習(xí)實例58 Python 100例 題目:畫圖,學(xué)用rectangle畫方形?! ?程序分析: rectangle(int left, int top, int right, int bottom) 參數(shù)說明:(left ,top )為矩形的左上坐標,(right,bottom)為矩形的右下坐標,兩者可確定一個矩形的大小 程序...
http://m.o2fo.com/python/python-exercise-example58.htmlPython 練習(xí)實例39 Python 100例 題目:有一個已經(jīng)排好序的數(shù)組?,F(xiàn)輸入一個數(shù),要求按原來的規(guī)律將它插入數(shù)組中。 程序分析:首先判斷此數(shù)是否大于最后一個數(shù),然后再考慮插入中間的數(shù)的情況,插入后此元素之后的數(shù),依次...
http://m.o2fo.com/python/python-exercise-example39.htmlPython 練習(xí)實例49 Python 100例 題目:使用lambda來創(chuàng)建匿名函數(shù)。 程序分析:無 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- MAXIMUM = lambda x,y : (x > y) * x + (x < y) * y MINIMUM = lambda x,y : (x > y) * y + (x < y) * x if __name__ == '__mai...
http://m.o2fo.com/python/python-exercise-example49.htmlPython 練習(xí)實例40 Python 100例 題目:將一個數(shù)組逆序輸出。 程序分析:用第一個與最后一個交換。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': a = [9,6,5,4,1] N = len(a) print a for i in range(len(a) / 2): a[i],a[N - ...
http://m.o2fo.com/python/python-exercise-example40.htmlPython 練習(xí)實例50 Python 100例 題目:輸出一個隨機數(shù)。 程序分析:使用 random 模塊。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- import random #生成 10 到 20 之間的隨機數(shù) print random.uniform(10, 20) 以上實例輸出結(jié)果為: 14.4012371357 Py...
http://m.o2fo.com/python/python-exercise-example50.htmlPython 練習(xí)實例60 Python 100例 題目:計算字符串長度?! ?程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- sStr1 = 'strlen' print len(sStr1) 以上實例輸出結(jié)果為: 6 Python 100例
http://m.o2fo.com/python/python-exercise-example60.htmlPython 練習(xí)實例41 Python 100例 題目:模仿靜態(tài)變量的用法。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- def varfunc(): var = 0 print 'var = %d' % var var += 1 if __name__ == '__main__': for i in range(3): varfunc() # 類的屬...
http://m.o2fo.com/python/python-exercise-example41.htmlPython 練習(xí)實例51 Python 100例 題目:學(xué)習(xí)使用按位與 & 。 程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': a = 077 b = a & 3 print 'a & b = %d' % b b &= 7 print 'a & b = %d' % ...
http://m.o2fo.com/python/python-exercise-example51.html抱歉,暫時沒有相關(guān)的文章
w3cschool 建議您: