辜 德 (Good) 的 Python 部 落 格
目 前 是 潮 州 高 中 的 數 學 老 師 , 偏 好 以 Python 來 解 決 數 學 問 題
總網頁瀏覽量
2018年12月14日 星期五
河內塔
Python Code:
def hanoi(n,A,B,C):
return [(A,C)] if n==1 else hanoi(n-1,A,C,B)+hanoi(1,A,B,C)+hanoi(n-1,B,A,C)
n =int(input("輸入河內塔的環數:"))
for i in hanoi(int(n), 'A', 'B', 'C'):
print("環由 %c 移至 %c " %i)
2018年12月13日 星期四
九九乘法表
Python Code:
#方法一
print('\n'.join(['\t'.join(['%dx%d=%d' % (a,b,a*b) for a in range(1,10)]) for b in range(1,10)]))
#方法二
for a in range(1,10):
for b in range(1,10):
print("%dx%d=%2d" % (b,a,b*a),end=" ")
print("")
2018年12月11日 星期二
正能量
2018年12月10日 星期一
正能量
2018年12月7日 星期五
負能量
2018年12月6日 星期四
正能量
2018年12月4日 星期二
負能量
較新的文章
較舊的文章
首頁
訂閱:
文章 (Atom)