2009年5月4日 星期一

Use python as calculator

定義變數 i 及初始值為4
i=4

加法
i+=4 (or i=i+4)
print("Integer i is "+str(i))

減法
i-=3 (or i=i-3)
print("Integer i is "+str(i))

乘法
i*=3 (or i=i*3)
print("Integer i is "+str(i))

除法
i/=5 (or i=i/5)
print("Integer i is "+str(i))

結果
Integer i is 8
Integer i is 5
Integer i is 15
Integer i is 3

沒有留言:

張貼留言