Python 練習實例32 Python 100例 題目:按相反的順序輸出列表的值。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- a = ['one', 'two', 'three'] for i in a[::-1]: print i 以上實例輸出結果為: three two one Python 1...
http://www.o2fo.com/python/python-exercise-example32.htmlPython 練習實例23 Python 100例 題目:打印出如下圖案(菱形): * *** ***** ******* ***** *** * 程序分析:先把圖形分成兩部分來看待,前四行一個規(guī)律,后三行一個規(guī)律,利用雙重for循環(huán),第一層控制行,第二層控制列。 程序源代碼:...
http://www.o2fo.com/python/python-exercise-example23.htmlPython 練習實例33 Python 100例 題目:按逗號分隔列表。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- L = [1,2,3,4,5] s1 = ','.join(str(n) for n in L) print s1 以上實例輸出結果為: 1,2,3,4,5 Python 100例
http://www.o2fo.com/python/python-exercise-example33.htmlPython 練習實例34 Python 100例 題目:練習函數(shù)調用。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- def hello_world(): print 'hello world' def three_hellos(): for i in range(3): hello_world() if __name__ == '__main__': three_hellos()...
http://www.o2fo.com/python/python-exercise-example34.htmlPython 練習實例35 Python 100例 題目:文本顏色設置。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m...
http://www.o2fo.com/python/python-exercise-example35.htmlPython 練習實例26 Python 100例 題目:利用遞歸方法求5!。 程序分析:遞歸公式:fn=fn_1*4! 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- def fact(j): sum = 0 if j == 0: sum = 1 else: sum = j * fact(j - 1) return sum for i in range(5): print '%d! = %d' %...
http://www.o2fo.com/python/python-exercise-example26.htmlPython 練習實例36 Python 100例 題目:求100之內的素數(shù)。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- from math import sqrt if __name__ == '__main__': N = 100 a = range(0,N) for i in range(2,int(sqrt(N))): for j in range(i + 1,N): if (a[i] ...
http://www.o2fo.com/python/python-exercise-example36.htmlPython 練習實例27 Python 100例 題目:利用遞歸函數(shù)調用方式,將所輸入的5個字符,以相反順序打印出來。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- def output(s,l): if l==0: return print (s[l-1]) output(s,l-1) s = raw_input(...
http://www.o2fo.com/python/python-exercise-example27.htmlPython 練習實例37 Python 100例 題目:對10個數(shù)進行排序。 程序分析:可以利用選擇法,即從后9個比較過程中,選擇一個最小的與第一個元素交換,下次類推,即用第二個元素與后8個進行比較,并進行交換。 程序源代碼: #!/usr/bin...
http://www.o2fo.com/python/python-exercise-example37.htmlPython 練習實例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://www.o2fo.com/python/python-exercise-example38.html抱歉,暫時沒有相關的微課
w3cschool 建議您:
抱歉,暫時沒有相關的視頻課程
w3cschool 建議您:
抱歉,暫時沒有相關的教程
w3cschool 建議您:
Python 練習實例32 Python 100例 題目:按相反的順序輸出列表的值。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- a = ['one', 'two', 'three'] for i in a[::-1]: print i 以上實例輸出結果為: three two one Python 1...
http://www.o2fo.com/python/python-exercise-example32.htmlPython 練習實例23 Python 100例 題目:打印出如下圖案(菱形): * *** ***** ******* ***** *** * 程序分析:先把圖形分成兩部分來看待,前四行一個規(guī)律,后三行一個規(guī)律,利用雙重for循環(huán),第一層控制行,第二層控制列。 程序源代碼:...
http://www.o2fo.com/python/python-exercise-example23.htmlPython 練習實例33 Python 100例 題目:按逗號分隔列表。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- L = [1,2,3,4,5] s1 = ','.join(str(n) for n in L) print s1 以上實例輸出結果為: 1,2,3,4,5 Python 100例
http://www.o2fo.com/python/python-exercise-example33.htmlPython 練習實例34 Python 100例 題目:練習函數(shù)調用。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- def hello_world(): print 'hello world' def three_hellos(): for i in range(3): hello_world() if __name__ == '__main__': three_hellos()...
http://www.o2fo.com/python/python-exercise-example34.htmlPython 練習實例35 Python 100例 題目:文本顏色設置。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m...
http://www.o2fo.com/python/python-exercise-example35.htmlPython 練習實例26 Python 100例 題目:利用遞歸方法求5!。 程序分析:遞歸公式:fn=fn_1*4! 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- def fact(j): sum = 0 if j == 0: sum = 1 else: sum = j * fact(j - 1) return sum for i in range(5): print '%d! = %d' %...
http://www.o2fo.com/python/python-exercise-example26.htmlPython 練習實例36 Python 100例 題目:求100之內的素數(shù)。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- from math import sqrt if __name__ == '__main__': N = 100 a = range(0,N) for i in range(2,int(sqrt(N))): for j in range(i + 1,N): if (a[i] ...
http://www.o2fo.com/python/python-exercise-example36.htmlPython 練習實例27 Python 100例 題目:利用遞歸函數(shù)調用方式,將所輸入的5個字符,以相反順序打印出來。 程序分析:無。 程序源代碼: #!/usr/bin/python # -*- coding: UTF-8 -*- def output(s,l): if l==0: return print (s[l-1]) output(s,l-1) s = raw_input(...
http://www.o2fo.com/python/python-exercise-example27.htmlPython 練習實例37 Python 100例 題目:對10個數(shù)進行排序。 程序分析:可以利用選擇法,即從后9個比較過程中,選擇一個最小的與第一個元素交換,下次類推,即用第二個元素與后8個進行比較,并進行交換。 程序源代碼: #!/usr/bin...
http://www.o2fo.com/python/python-exercise-example37.htmlPython 練習實例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://www.o2fo.com/python/python-exercise-example38.html抱歉,暫時沒有相關的文章
w3cschool 建議您: