數(shù)字和數(shù)學(xué)計(jì)算
- 輸入:
# -- coding: utf-8 --
print "I will now count my chickens:"
print "Roosters", 100 - 25* 3 % 4
print "Now I will count the eggs:"
print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6
print "Is it true that 3 + 2 < 5 - 7?"
print 3 + 2 < 5 - 7
print "What is 3 + 2?", 3 + 2
print "What is 5 - 7?", 5 - 7
print "Oh, that's why it's False."
print "How about some more."
print "Is it greater?", 5 > -2
print "Is it greater or equal?", 5 >= -2
print "Is it less or equla?", 5 <= -2
- 運(yùn)行:

附加題
- 浮點(diǎn)數(shù)(floating point number)
<strong>“浮點(diǎn)數(shù)”的定義是相對(duì)于“定點(diǎn)數(shù)”來(lái)說(shuō)的。</strong>
在計(jì)算機(jī)內(nèi)部,數(shù)據(jù)以二進(jìn)制的形式存儲(chǔ)和運(yùn)算,而計(jì)算機(jī)內(nèi)表示的數(shù),又被分成整數(shù)和實(shí)數(shù)兩大類(lèi)。
其中整數(shù)一般用定點(diǎn)數(shù)表示,定點(diǎn)數(shù)指小數(shù)點(diǎn)在數(shù)中有固定的位置(一般來(lái)說(shuō)整數(shù)的小數(shù)點(diǎn)都在最末位數(shù)后)。
實(shí)數(shù)一般用浮點(diǎn)數(shù)表示,因?yàn)樗男?shù)點(diǎn)位置不固定。浮點(diǎn)數(shù)是既有整數(shù)又有小數(shù)的數(shù),純小數(shù)可以看作實(shí)數(shù)的特例。
- 使用浮點(diǎn)數(shù)重寫(xiě)一遍 ex3.py,讓它的計(jì)算結(jié)果更準(zhǔn)確(提示: 20.0 是一個(gè)浮點(diǎn)數(shù))。
# -- coding: utf-8 --
print "I will now count my chickens:"
print "Roosters", 100.0- 25.0* 3.0 % 4.0
print "Now I will count the eggs:"
print 3.0 + 2.0 + 1.0 - 5.0 + 4.0 % 2.0 - 1.0 / 4.0 + 6.0
print "Is it true that 3.0 + 2.0 < 5.0 - 7.0?"
print 3.0 + 2.0 < 5.0 - 7.0
print "What is 3.0 + 2.0?", 3.0 + 2.0
print "What is 5.0 - 7.0?", 5.0 - 7.0
print "Oh, that's why it's False."
print "How about some more."
print "Is it greater?", 5.0 > -2.0
print "Is it greater or equal?", 5.0 >= -2.0
print "Is it less or equla?", 5.0 <= -2.0

Paste_Image.png