python簡單習題系列2

熟悉python中的常用運算符號,瞭解python的math庫模塊。

並分別求出表達式 12*34+78-132/6、(12*(34+78)-132)/6、(86/40)**5的值。
並利用math模塊進行數學計算,分別求出145/23的餘數,0.5的sin和cos值


#coding:utf-8
'''
基本表達式運算,數學運算
'''

x = 12*34+78-132/6
y = (12*(34+78)-132)/6
z = (86/40)**5

print ('12*34+78-132/6 = %d' % x)
print ('(12*(34+78)-132)/6 = %d' % y)
print ('(86/40)**5 = %d' % z)


#導入數學計算的模塊
import math   

a = math.fmod(145, 23)  #求145/23 的餘數
b = math.sin(0.5)
c = math.cos(0.5)

print ('145/23的餘數是: %d' % a)
print ('0.5的sin值是: %f' % b)
print ('0.5的cos值是: %f' % c)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章